Basic Linux Commands
Basic Linux Commands
Linux Fundamentals
Linux Commands
Linux provides a CLI (Command Line Interface) to communicate with the OS. Here are the most
basic of the Linux Commands.
1. pwd
syntax:
$ pwd
2. echo
syntax:
$ echo "<text>"
3. clear
Clears the terminal screen. Contents will not actually be deleted in this case, only scrolled down.
You can also clear the screen by pressing Ctrl+L on the keyboard.
syntax:
$ clear
1. cp
Copies files and directories. A copy of the file/directory copied, still remains in the working
directory.
syntax:
Command Explanation
2. mv
Moves files and directories from one directory to another. The file/directory once moved, is
deleted from the working directory.
syntax:
Command Explanation
Enters interactive mode; CLI asks before
mv -i
overwriting files
3. rm
Removes files from a directory. By default, the rm command does not remove directories. Once
removed, the contents of a file cannot be recovered.
syntax:
$ rm <flag> {filename}
Command Explanation
4. grep
Searches for a particular string/word in a text file. This is similar to “Ctrl+F” but, executed via a CLI.
syntax:
Command Explanation
5. cat
Used to read, modify or concatenate text files. It also displays file contents.
syntax:
Command Explanation
This is used to add line numbers to non-blank
cat -b
lines
cat -n This is used to add line numbers to all lines
This is used to squeeze blank lines into one
cat -s
line
cat –E Show $ at the end of line
1. ls
syntax:
$ ls <flag>
Command Explanation
2. cd
syntax:
$ cd /pathname/
Command Explanation
3. sort
Sorts the results of a search either alphabetically or numerically. Files, file contents and directories
can be sorted using this command.
syntax:
Command Explanation
4. mkdir
syntax:
Command Explanation
5. rmdir
Removes a specified directory. Although by default, it can only remove an empty directory, there
are flags which can be deployed to delete the non-empty directories as well.
syntax:
Command Explanation
User Permissions
1. su
syntax:
$ su
2. su <username>
syntax:
$ su <username>
3. sudo
syntax:
$ sudo <command>
Command Explanation
4. chmod
Used to change the access permissions of files and directories. Consider the example below.
On trying to run the newly created file named chmodtestfile.sh, an error is thrown. After
modifying the permissions of the file using the said Linux command, it turns executable.
syntax:
Installing Packages
Stable versions of most software’s will already be available in Linux repositories. Here are the Linux
Commands to install them.
1. Install packages
syntax:
syntax:
syntax:
Zipped Files
When you download a package from the internet, the downloaded file comes in compressed form.
Here are a few commands to decompress and compress files in Linux.
1. tar
syntax:
syntax:
This command, on running at the slave node, will give remote access to the master.
syntax:
This command, on running at the master, will give remote access to the slave node.
syntax: