Short linux most used commands guide

This is a small usage guide of the most used linux commands. If you would like to know more about the commands options please consult the linux man pages.

Command: ls [option] [file]

Description: List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor –sort.

Usage examples:
1. To list the content of the current directory with one entry per line and show hidden files:
$ ls -la
2. To list only the directories in the current folder:
$ ls -d */
3. To list the contents of all sub directories:
$ ls */

Command: rm [options] [file]

Description: rm removes each specified file. By default, it does not remove directories. If the -I or –interactive=once option is given, and there are more than three files or the -r, -R, or –recursive are given, then rm prompts the user for whether to proceed with the entire operation. If the response is not affirmative, the entire command is aborted.
Otherwise, if a file is unwritable, standard input is a terminal, and the -f or –force option is not given, or the -i or –interactive=always option is given, rm prompts the user for whether to remove the file. If the response is not afirmative, the file is skipped.

Usage examples:
1. To remove a file called myfile.txt:
$ rm myfile.txt
2. To remove all .txt files:
$ rm *.txt
3. To remove all files and subdirectories in the current directory:
$ rm -r *

Command: mv [options] source dest

Description: Rename source to dest, or move source(s) to dest

Usage examples:
1. To rename a file myfile.txt to mynewfile.txt:
$ mv myfile.txt mynewfile.txt
2. To move a file to a directory:
$ mv myfile.txt mydirectory/

Command: cp [options] source dest

Description: Copies files from source to dest

Usage examples:
1. To make a file duplicate in current folder:
$ cp myfile.txt myfile_copy.txt
2. To copy a file from one folder to another:
$ cp /var/log/myfile.log /home/armino/backup/myfile.log.bak
3. To copy all files and subdirectories from a given folder use:
$ cp -r /var/log/* /home/armino/backup/

Command: mkdir [options] directory(ies)

Description: Create the directory(ies), if they do not already exist.
Usage examples:
1. To create a MyDir folder in curent path:
$ mkdir MyDir
2. To create a MyDir1 and MyDir2 in /var/www/html:
$ mkdir /var/www/html/MyDir1 /var/www/html/MyDir2

Command: tar <operation> [options]

Description: tar is an archiving program designed to store and extract files from an archive file known as a tarfile. A tarfile may be made on a tape drive, however, it is also common to write a tarfile to a normal file. The first argument to tar must be one of the options Acdrtux, followed by any optional functions.
The final arguments to tar are the names of the files or directories which should be archived. The use of a directory name always implies that the subdirectories below should be included in the archive.

Usage examples:
1. Creating a .tar.gz of the logs from /var/log:
$ tar cvzf backup.tar.gz /var/log/*
2. Extracting files from a .tar.gz archive:
$ tar xvfz backup.tar.gz

Command: tail [option] [file]

Description: Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name. With no FILE, or when FILE is -, read standard input.

Usage examples:

1. To display last 15 lines of a file use the following syntax:
$ tail -15 myfile.txt

2. To display the last 50 bytes of a file use the following syntax:
$ tail -c 50 myfile.bin

Command: wall [-n] [file]

Description: Wall sends a message to everybody logged in with their mesg permission set to yes. The message can be given as an argument to wall, or it can be sent to wall as standard input. When using the standard input from a terminal, the message should be terminated with the EOF key (usually Control-D).
The length of the message is limited to 20 lines. For every invocation of wall a notification will be written to syslog, with facility LOG_USER and level LOG_INFO.

Usage examples:
1. Input text from console:

$ wall
$ Type your first message line here
$ Here goes the second line
$ If you are ready type CTRL+D on the next line
$ [CTRL+D]

2. Input text from file:
$ wall message.txt

VN:F [1.9.11_1134]
Rating: 8.3/10 (8 votes cast)
Short linux most used commands guide, 8.3 out of 10 based on 8 ratings

About Armino

This website is about me, my experiences, my hobbies and my friends. If you are interested in my professional profile you can check it on LinkedIn.