Skip to content

Bash basics commands

File and Directory commands for beginners

  • cat file.txt: Displays the contents of the file file.txt.
  • cd /path/to/directory: Changes the current directory to the /path/to/directory.
  • cp SOURCE DEST: Copies the file or directory SOURCE and pastes it to a DEST location; i.e. cp examplefile.txt /home/user/office/ copies examplefile.txt in the current directory and pastes it into the /home/user/ directory. If the file is not in the current directory, add the path of the file’s location (i.e. cp /home/user/documents/examplefile.txt /home/user/office/ copies the file from the documents directory to the office directory).
  • ls -l: Lists files in the current directory, along with file size, date modified, and permissions.
  • mkdir test_directory: Creates a new directory named test_directory inside the current directory.
  • mv SOURCE DEST: Moves the file or directory named SOURCE to a DEST location. For example, mv myfile.txt /home/user/office/ move myfile.txt from the current directory to the /home/user/office directory. If the file is not in the current directory, add the path of the file’s location (i.e. cp /home/user/documents/examplefile.txt /home/user/office/ moves the file from the documents directory to the office directory). This command can also be used to rename files (basically rename a file is same action than moving this file in the same directory). For example, mv myfile.txt newfile.txt renames myfile.txt to newfile.txt.
  • rm file.txt: Deletes the file file.txt.
  • rmdir test_directory: Deletes the directory test_directory (only if it is empty).
  • scp user1@10.0.1.1:/some/path/file.txt user2@10.0.1.2:/some/path/file.txt: Copies a file over SSH. Can be used to download a file from a machine to another. user@10.0.1.2 is the username and local IP address of the machine (optional for current machine), and /some/path/file.txt is the path and file name of the file on this machine. ➮ documentation on ssh.
  • touch file.txt: Creates a new, empty file named file.txt in the current directory.