Linux Terminal Commands That Everyone Should Know

Yogesh Birla
3 min readJan 6, 2022

--

Shell command is a powerful tool for improving a developer’s productivity.

Here are the most useful shell commands you should know

1. ls

List directory contents

The ls command allows you to quickly view all files within the specified directory.

  • Syntax: ls [option(s)] [file(s)]
  • Common options: -a, -l

ls -l : To show long listing information about the file/directory.

ls -a : To show all the hidden files in the directory.

2. echo

Prints text to the terminal window

Echo is also particularly useful for showing the values of environmental variables

Syntax: echo [option(s)] [string(s)]

  • Common options: -e, -n

echo -e String : enables the interpretation of special characters in string.

echo -n String : this option is used to omit echoing trailing newline .

3. touch

Creates a empty file without opening it

You can create as many files as you want in a single command.

  • Syntax: touch [option(s)] filename
  • Common options: -a, -m, -r, -d

-a : This command is used to change access time only.

-m : This is used to change the modification time only.

-r : This command is used to use the timestamp of another file.

-d : This is used to update access and modification time.

4. mv

moves/renames a file or directory

  • Syntax: mv [option(s)] source destination
  • Common options: -f ,-n

-f : option overrides this minor protection and overwrites the destination file forcefully and deletes the source file.

-n : mv prevent an existing file from being overwritten.

5. cp

copies a file or directory

  • Syntax: cp [option(s)] source destination
  • Common options: -f

-f : to enable force copy , it overrides if file already exists

-p : the time of the last data modification and the time of the last access, the ownership and the file permission-bits is preserved with this option.

-R : to indicate the recursive copying of directories.

-i(interactive): i stands for Interactive copying.

6. mkdir

Create a new directory

mkdir is a useful command you can use to create directories. Any number of directories can be created simultaneously which can greatly speed up the process.

  • Syntax: mkdir [option(s)] directoryname
  • Common options: -v, -p

-v : It displays a message for every directory created.

-p : It enables the command to create parent directories as necessary.

7. man

Print manual or get help for a command

The man command is manual and is very useful when you need to figure out what a command does.

  • Syntax: man [option(s)] keyword(s)
  • Common options: -w, -f

-f : This option gives the section in which the given command is present.

-w : This option returns the location in which the manual page of a given command is present.

8. rmdir

delete a directory

rmdir is a useful command you can use to delete directories. Any number of directories can be deleted simultaneously which can greatly speed up the process.

  • Syntax: rmdir [option(s)] directoryname
  • Common options: -v

-v : It displays a message for every directory deleted.

9. pwd

Prints Working Directory

It prints the path of the working directory, starting from the root.

10. cat

cat(concatenate) used for many purposes

following are some of the users of the cat command :

  1. prints the contents of file
cat filename.txt

2. prints the contents of file with line numbers

cat -n filename.txt

3. append content to a existing file

cat >> filename.txt

4. append content of one file at the end of other file

$cat file1 >> file2

Conclusion

Linux has lots of commands that we should know about.

We should know how to traverse directories, list files, and copy/moves files.

Thank you !!!

--

--