Linux tutorial - Essential commands

The shell is a mighty beast of the Linux OS and can be very powerful and handy to perform day to day activities.

Usually a command is of the following syntax

Command -[option] [Arguments]

1. ls

It is used to list the files in the current directory. In order to view the hidden files use
-a - Displays hidden files.
ls *.pdf - To display only the pdf files.

2. touch

It is used to create a file.
touch abc.txt creates a text file. Various other extensions can also be used

3. rm

It is used to delete a file.
rm abc.txt - Removes abc text file.
rm *.txt - Removes all files with txt extension
rm abc.* - Removes all files with the name abc. Eg abc.txt, abc.pdf, abc.mp3.
rm *.* - Removes all files of all types
rm -rf - Removes recursively all the files. Very dangerous.

4. mkdir

It is used to create a directory.
mkdir hello - Creates a directory named hello

5. rmdir

It removes the directory
rmdir hello - Removes hello directory

6. sudo apt-get install

It is used to install a software package from the official repository.  It asks for password if you are not a root user.
sudo apt-get install firefox - It installs firefox

7. pwd

Got stuck and don't know the current directory. It prints the current directory.
pwd

8. Launch an application

To launch an application just type the name of the application and press enter.
Firefox - It starts firefox.
Firefox www.google.com - It launches firefox with google page.
evince abc.pdf - It launches the document viewer with the pdf

9. TAB to autocomplete

If you are caught in a situation to type a very long file just type the characters and press tab to autocomplete.

to open qwertyuiop.pdf type evince qwe[tab] it autocompletes the filename. If  more variations exist press TAB twice to get the list of files with the match.
If you have asdf.pdf, asdfgh.pdf press evince asd[tab][tab] it lists asdf.pdf asdfgh.pdf

10. History
Type history to have a history of the entered commands.
to implement the 4th command type ![num] and enter to execute the command

No comments:

Post a Comment

UA-42852783-1