Software & Apps Linux 106 106 people found this article helpful 10 Essential Linux Commands for Navigating Your File System Move around the filesystem with ease using these common shell commands by Gary Newell Writer Gary Newell was a freelance contributor, application developer, and software tester with 20+ years in IT, working on Linux, UNIX, and Windows. our editorial process Gary Newell Updated on October 01, 2020 Linux Switching from Windows Tweet Share Email Hopping about a Linux filesystem is easy even if you're working from a shell prompt. It provides commands to find out which directory you are in, which directory you were previously in, how to navigate to other folders, how to get back home, how to create files and folders, and how to create links. 01 of 10 Which Folder Are You In? To find out which folder you are in, use the following command: pwd The results returned by pwd may differ depending on whether you are using the shell version of pwd or the one installed in your /usr/bin directory. In general, it will print something along the lines of /home/username. 02 of 10 What Files and Folders Are Under the Current Directory? Display the files and folders in the current directory by using the ls command. ls On its own, the ls command lists all the files and folders in the directory except for those beginning with a period. To see all the files including hidden files (those starting with a period), use the following switch: ls -a Some commands create backups of files that begin with the tilde metacharacter (~). If you don't want to see the backups when listing the files in a folder, use the following switch: ls -B The most common use of the ls command is as follows: ls -lt This command provides a long listing sorted by modification time, with the newest first. Other sort options include by extension, size, and version: ls -lUls -lXls -lv The long listing format gives you the following information: PermissionsNumber of inodes for the file (see hard links)OwnerPrimary groupFile sizeLast access timeFile/folder/link name 03 of 10 How to Move to Other Folders To move around the file system use the cd command. The Linux file system is a tree structure. The top of the tree is denoted by a slash (/). Under the root directory, you will find some or all of the following folders. The bin folder contains commands that can be run by any user such as the cd command, ls, mkdir, etc. The sbin contains system binaries. The usr folder stands for unix system resources and also contains a bin and sbin folder. The /usr/bin folder contains an extended set of commands. Similarly, the /usr/sbin folder contains an extended set of system commands. The boot folder contains everything required by the boot process. The cdrom folder is a mapping location for optical media. The dev folder contains details about all the devices on the system. The etc folder is generally where all the system configuration files are stored. The home folder is generally where all the user folders are stored and for the average user, is the only area they should be concerned about. The lib and lib64 folders contain all the kernel and shared libraries. The lost+found folder contains files that no longer have a name, which have been found by the fsck command. The media folder is where mounted media such as USB drives are located. The mnt folder is also used to mount temporary storage such as USB drives, other file systems, ISO images, etc. The opt folder is used by some software packages as a place to store the binaries. Other packages use /usr/local. The proc folder is a system folder used by the kernel. You don't really need to worry about this folder too much. The root folder is the home directory for the root user. The run folder is a system folder for storing system runtime information. The srv folder is where you would keep things like web folders, mysql databases, and subversion repositories, etc. The sys folder contains a folder structure to provide system information. The tmp folder is a temporary folder. The var folder contains a whole wealth of stuff specific to the system, including game data, dynamic libraries, log files, process IDs, messages, and cached application data. To move to a particular folder use the cd command as follows: cd /home/username/Documents 04 of 10 How to Navigate Back to the Home Folder Get back to your home folder from anywhere else in the system using the cd ~ command. cd ~ 05 of 10 How to Create a New Folder To create a new folder you can use the mkdir command: mkdir foldername 06 of 10 How to Create Files Linux provides an incredible number of ways for creating new files. To create an empty file, use the following touch command: touch filename The touch command is used to update the last access time for a file but on a file that doesn't exist, it has the effect of creating it. You can also create a file using the cat command: cat > filename You can now enter text on the command line and save it to the file using Ctrl+D. A better way of creating files is to use the nano editor. This handy tool offers a full suite of text-editing features. 07 of 10 How to Rename and Move Files Around the File System The simplest way to rename a file is to use the mv command. mv oldfilename newfilename Use the mv command to move a file from one folder to another as well. mv /path/of/original/file /path/of/target/folder To rename a lot of files that match a similar pattern, use the rename command. rename expression replacement filename(s) For example: rename "gary" "tom" * This command replaces all files in the folder with gary in it with tom. So a file called garycv will become tomcv. The rename command doesn't work on all systems. The mv command is safer. 08 of 10 How to Copy Files To copy a file using Linux, use the cp command as follows. cp filename filename2 The above command will copy filename1 and call it filename2. Use the copy command to copy files from one folder to another. For example: cp /home/username/Documents/userdoc1 /home/username/Documents/UserDocs The above command copies the file userdoc1 from /home/username/Documents to /home/username/Documents/UserDocs 09 of 10 How to Delete Files and Folders Delete files and folders using the rm command: rm filename To remove a folder, use the following switch: rm -R foldername The above command removes a folder and its contents including sub-folders. 10 of 10 What Are Symbolic Links and Hard Links? A symbolic link is a file that points to another file. A desktop shortcut is basically a symbolic link. You might, for example, have the following file on your system: /home/username/document/accounts/useraccounts.doc To access that document from the home/username folder, create a symbolic link using the following command: ln -s /home/username/documents/accounts/useraccounts.doc /home/username/useraccounts.doc You can edit the useraccounts.doc file from both places but when you edit the symbolic link, you are actually editing the file in the /home/username/documents/accounts folder. A symbolic link can be created on one filesystem and point to a file on another file system. Essentially, a symbolic link really just creates a file that has a pointer to the other file or folder. A hard link, however, creates a direct link between the two files. Essentially they are the same file but with just another name. A hard link provides a good way of categorizing files without taking up further disk space. Create a hard link using the following syntax: ln filenamebeinglinked filenametolinkto The syntax is similar to that of a symbolic link but it doesn't use the -s switch.