Some Usefull Linux Commands

Using man pages:

man command_name, then use the cursors to scroll up and down. To quit type “q”.

Adding a new user:

Add a new user: useradd user_name
set a password for this user: passwd user_name

File permissions:

chmod u+r file_name: gives the user the permission to read.
chmod g+r,o-x file_name: gives the group the permission to read and make the others having no permission to execute.
chmod u+w file_name: gives the user the permission to write to file_name.

Modifying the owner of a file or directory:

chown user_name file_name

copying the content of a directory including the content of its subdirectories:
cp -r source destination

Remove the subdirectories and their content without prompting:
rm -rf filename

Renaming a file:
mv old_name new_name

Finding a file:

find -name “*txt*” / -print : prints to the screen the location of all the files whose name contains “txt”.

Installing a package:
The first thing to do is to find what are the packages available. This can be done by the following command:
urpmi -y str
This command shows all the rpms that contain the string str.
then you can choose the programs to install by using the following command:
urpmi prg where prg is program listed in the output of the previous command.

Locating where a command is:

Locating where is a command can be helpful for adding it to the path for example.
the following command finds where the gcc comand is located: whereis gcc gcc: /usr/bin/gcc /usr/bin/gcc3.3-version /usr/share/man/man1/gcc.1.bz2

Adding a directory to the path:

I have just installed gcc (the gnu C compiler) in my machine. I can run the gcc command for compiling programs as a root but not as a user. The previous command output shows that the gcc command is located in /usr/bin/. For allowing a user to run gcc i have to add the following statement to the .bash_profile file of that user: PATH=$PATH:/usr/bin. When adding a directory to the path variable ensure that the statement you add is before the “export PATH” statement.

Extracting .tar.gz files:

tar -C directory_name -xvzf file.tar.gz
This command extracts the content of the file to the directory directory_name.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s