10 Basic and Important Linux Commands

If you are new Linux user then you must know these basic linux commands as a beginers. There are lots of other commands, more sophisticated commands – which you will learn one day. But here i am going to start with some basic commands.


1- ls - List all directory and files
The ls command is used for viewing files, folders and directories. Usage
#ls /somedir
This command will show the user all of the folders stored in the overall somedir folder.

2- cd – Change directory
The ‘cd’ command should be used followed by the name of a directory including the full path to that directory. If you execute ‘cd’ without arguments the working directory will be switched to your ‘home directory’.
    # cd /path/to/directory_name/

To move one directory up, you can use the shortcut command:
    # cd ..

3- cat – Shows the contents of files to the screen
   # cat file.txt
# Hello World

Also this command can be used to count the number of lines, words and characters in a file:

# cat | wc -l
– number of lines

# cat | wc -w
– number of words

# cat | wc -c
– number of characters

To search for a word in a file you can use:
# cat | grep

4- mv – Moves files and directories from one directory to another or renames a file or directory
Move ‘file’ from ‘/root’ to ‘/tmp’ directory
# mv /root/file /tmp/

Rename ‘file1’ to ‘file2’
# mv file1 file2

5- passwd – change user password

# passwd
If you execute just ‘passwd’ without specifying the username, you will change your root password.
Note: Never use passwords that are easily guessable, such as passwords based upon names, street addresses, dictionary words, significant dates, etc… A strong password consists of a combination of letters (both upper and lower case), numbers and special characters and it should be at least 8 characters long.

6- mkdir – Creates directory(ies) if they don’t already exist

# mkdir

# mkdir /var/www/

7- rmdir – remove directory
# rmdir testdirectory

The example command removed the directory “testdirectory”.
It should be noted: both the mkdir and rmdir commands make and remove directories. They do not make files and they will also not remove a directory which has files in it. The mkdir will make an empty directory and the rmdir command will remove an empty directory.

8- rm – Remove files
The rm command – remove – like the rmdir command is meant to remove files from your Linux OS. Whereas the rmdir command will remove directories and files held within, the rm command will delete created files.

# rm testfile.txt
The aforementioned command removed testfile.txt. Interestingly, whereas the rmdir command will only delete an empty directory, the rm command will remove both files and directories with files in it. This said, the rm command carries more weight than the rmdir command and should be used with more specificity.

9- locate – Find a file
locate command is meant to find a file within the Linux OS. If you don’t know the name of a certain file or you aren’t sure where the file is saved and stored, the locate command comes in handy.
# locate -i *red*house**city*

The stated command will locate an file with the a file name containing “Red”, “House” and “City”. A note on the input: the use of “-i” tells the system to search for a file unspecific of capitalization (Linux functions in lower case). The use of the asterik “*” signifies searching for a wildcard. A wildcard tells the system to pull any and all files containing the search criteria.

By specifying -i with wildcards, the locate CLI command will pull back all files containing your search criteria effectivley casting the widest search net the system will allow.

10- clear – The clear command does exactly what it says. When your Linux CLI gets all mucked up with various readouts and information, the clear command clears the screen and wipes the board clean. Using the clear command will take the user back to the start prompt of whatever directory you are currently operating in. To use the clear command simply type clear.