While most operating systems can be used without venturing into command line, Linux and other UNIX-like Operating Systems are frequently used without Graphical User Interfaces (GUI), it is essential that a beginning Linux user or even a seasoned sysadmin be familiar and know how to navigate UNIX-like Operating Systems.
This guide will introduce some of the most basic commands and options needed to navigate the Linux file systems that happen to also be some of the most frequently used commands in UNIX-like operating systems. This is not an all-inclusive list or will discuss all available options, but it should assist in at least getting familiar with commands include ls, cd, pwd, clear, cp, mv, mkdir, rm, rmdir, and touch.
The Linux File System
The Linux file system follows a specific format. The file system starts at what is called the "root" (also coincidentally the word root also refers to the system administrator account from which all permissions in UNIX-like OSs given) represented by a forward slash (
/) and then each subsequent folder is separated by another forward slash (
..(The parent folder to this current folder)
.fileorfoldername(Hidden file or folder)
There are absolute paths and relational paths. Absolute paths start from the root and then list all folders/directories until they reach the folder/directory intended. Relational paths start from the current folder/directory and then move back/up or foward/down the directory tree. Relational paths can also use an environmental variable like the ~ (tilde) to represent the home directory and then up or down the directory tree.
/home/username/.hiddenfolder/(Absolute path to the .hidden folder in the users home directory)
~/.hiddenfolder(Not all UNIX-like OSs require that there be a forward slash (/) after the last foldername)
$HOME/.hiddenfolder(Same as the previous but with a different environmental variable)
~/file(This is a file inside the home directory)
../otheruserhome/file(Assuming you are already in the /home/username/ folder)
Understanding the format for file system representation will help for identifying paths further in the tutorial.
List Files/folders (ls)
This is likely the first command that most users will learn to use as they get introduced to Linux. This command lists the contents of a directory. While the command alone will result in a tab-delimited word-wrapping list of files and folders, some options can be added to include information about the files and folders such as permissions and can even improve formating of output.
ls [options] [path](path is assumed to be the current directory if left blank)
file1 file2 file3 file4 file5
(option -a lists all files)
$ ls -a
. .. .bash_history .bash_logout .bashrc .cache .profile .vim .viminfo
(options -a1 lists all files 1 per line)
$ ls -a1
(options -al will list all files in "long listing format")
$ ls -al
drwxr-xr-x 4 administrator administrator 4096 Mar 17 13:37 .
drwxr-xr-x 5 root root 4096 Mar 5 20:21 ..
-rw------- 1 administrator administrator 2248 Mar 6 11:58 .bash_history
-rw-r--r-- 1 administrator administrator 220 Mar 3 15:53 .bash_logout
-rw-r--r-- 1 administrator administrator 3486 Mar 3 15:53 .bashrc
drwx------ 2 administrator administrator 4096 Mar 3 15:57 .cache
-rw-r--r-- 1 administrator administrator 675 Mar 3 15:53 .profile
drwxr-xr-x 2 root root 4096 Mar 5 21:07 .vim
-rw------- 1 root root 1092 Mar 6 11:11 .viminfo
(adding option -h will change the numbers into "human readable" format)
$ ls -alh
drwxr-xr-x 4 administrator administrator 4.0K Mar 17 13:37 .
drwxr-xr-x 5 root root 4.0K Mar 5 20:21 ..
-rw------- 1 administrator administrator 2.2K Mar 6 11:58 .bash_history
Other frequently used options are"
ls -R (will print the current folder contents and the contents of all subfolders)
ls -S will sort by file size
Change Directory (cd)
Print Working Directory (pwd)
Clear Screen (clear)
Make Directory (mkdir)
Remove Directory (rmdir)
Create file (touch)