Useful Linux Commands – Basic Navigation

Here are some basic Linux commands which will surely help you as you begin to explore Linux. To start with, we will discuss some basic navigation commands.

Note: All of these commands are meant to be run from a terminal. In most Linux distributions, the terminal can be accessed as an “Accessory” in your gui menus. Alternatively, you can normally get to a terminal by pressing Ctrl-Alt-F1 (or F2, F3…to get to your various “terminals”).

Here is just a starter list of some useful commands you should become familiar with. Although the Linux GUIs have progressed significantly in recent years, it is still much more convenient and efficient to do some things from the old command line.

This article is not meant to be a full manual for any of these commands. In fact, manuals have already been written for them and can be easily accessed by typing “man” before any of these commands (ex: “man ls”). It’s just difficult sometimes to know where to start and what to search for. This is the purpose of this article.

For each command, I will give you a description of what the program is used for, what it does, and a brief example. Each command typically has many options which can be used. Options, in Linux, are passed to the program from the command line by preceding the “option” with a ‘-‘ or ‘–‘. Sometimes an option is either on or off, for example “ls -h” will “list” the files in a directory with human readable sizes (MB, kB)and “ls -R” will recursively list all subdirectories. Other commands take arguments such as “du –max-depth=1” which will limit the display of subdirectories to one, when looking at how much data is in each directory read this post here.

Basic Navigation

ls – List

Basic List function which lists all of the files in a particular directory or location. Typing “ls” will list files in the current directory excluding hidden files, whereas “ls /home/username” will print all files in the /home/username directory

Syntax: $ ls

Ex: To display all of the files in the current directory, including hidden files

$ ls -A

cd – Change Directory

Change the current directory. Note that if you put a ‘/’ in front of your path, it will be treated as an absolute path. If there is no ‘/’ at the beginning of your path, then the path will figure it is a subdirectory of your current directory. Here are some common examples.

Syntax: $ cd [directory]

Ex1: Change the directory to /home

$ cd /home

Ex2: Change the diretory to username subdirectory

$ cd username

Ex3: Go “up” one directory

$ cd ..

man – Manual

Displays the manual pages for various linux commands. You should pass man one argument, being the command you are interested in knowing more about, for example $ man locate or $ man cp to find more information about the program.

To navigate through the man pages, you can always use your up and down arrow, you can also press the space bar to advance one page or type ‘q’ to quit.

Syntax: man [command] Ex: Display the man page for the “cp” program

$ man cp

cp – Copy Copies files from one location to another. You can either copy from one file to another or many files to a directory. If you pass cp a list of files, the last file must be the destination directory. Note that cp will create a new copy of the file and not rename or “move” the file. Also note that you may wish to use the ‘-v’ option when copying many files to see the progress as you go along.

Syntax: cp [source] [destination]

Ex1: Copy file1 to file2.

$ cp file1 file2

Ex2: Copy three files to dest_directory

$ cp file1 file2 file3 dest_directory

Ex3: Copy all files in the current directory to /tmp

$ cp * /tmp

Ex4: Copy all files in the current directory to /tmp while displaying the name of each files as it is being copied

$ cp -v * /tmp

mv – Move

Similar to the DOS command “rename” and can be used to change the name or location of file. Move does not make a duplicate copy of the file and is typically vary fast if moving files to different areas on the same drive or mount point.

Sytanx: mv [file] [destination]

Ex1: Move old_file to new_filename

$ mv old_file new_filename

Ex2: Move all files into /tmp

$ mv * /tmp

Ex3: Move file1 to the parent directory

$ mv file1 ../

rm – Remove File

Can be used to remove or delete files. Either one or many files can be removed at a time. Note, you cannot simply remove a directory using the rm command unless doing a recursive delete.

Syntax: rm [filename]

Ex1: Remove file1

$ rm file1

Ex2: Remove all jpeg files from the current directory

$ rm *.jpg

Ex3: Remove all jpeg files from the current directory without being prompted before each file is deleted

$ rm -f *.jpg

Ex3: Remove the directory bad_dir and all files beneath it

$ rm -R bad_dir

rmdir – Remove Directory

Removes an empty directory from the file system. Note: This command will return an error if the directory is not empty.

Syntax: rmdir [directory]

Ex1: Remove my_directory

$ rmdir my_directory

I hope that you find these commands helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *