Latest tutorial: Making a Movieclip face another Movieclip or point on the stage | Ask Tutorial5!
 

Basic Linux Shell commands

(12 votes)
Written by Michael D.   
When opening a shell, your will be logged in with your active account to your home directory (this is usually in /home/user_name).

Note that every command has lots of options available. To see all the manual pages for the specific command, simply type "man <command>". It is important to understand that under Linux operating systems, commands are case-sensitive. This means that "A" is different from "a".

To go through the file system, use:

 

- pwd - Prints out on the screen the working directory (eg /etc/ssh)
- cd - changes directory (eg cd .. - goes up one dir; cd etc - enters /etc dir)
- ls - lists the content of the directory
- mkdir - creates a new directory (mkdir dir_name)
- touch - creates a new file (touch file_name)
- rmdir - removes a directory (rmdir dir_name)
- cp - copies a file/directory (cp source_file destination_file)
- mv - moves a file/directory - also used for renaming a file or directory (mv old_location new_location or mv old_name new_name)
- rm - removes files (rm file_name)

To search a file, you can use

- find <search_criteria> (used for filenames)
- grep <search_criteria) to search for content in the file.

To view a file, you can use

- more <filename> - will display a file page by page
- cat <filename> - displays all the file
- head <filename> - displays the first lines
- tail <filename> - displays the last lines (useful for example when you want to view the last information logged in a file by the system for example)

To edit a file you must use a built-in editor from the command-line. Generally, this is vi and it's used with the syntax vi <filename>.

To uncompress an archive (usually tar.gz) you must use the tar command with the syntax tar -xvzf <file_name>.

To print a file, use lpr <filename> command. Note that you must have some daemons up and running to manage the printer. Usually this is cups (Common UNIX Printing System) that comes with all major distributions.
To remove a file from printer queue (you can list the queue with lpq command) you can use lprm <filename>.

To mount/unmount (add in your file system as accessible media) use:

- mount /mnt/floppy - to mount floppies
- umount /mnt/floppy - to unmount floppie
- mount /mnt/cdrom - to mount CD-ROMs
- mount /mnt/cdrom - to unmount CD-ROMs

They usually mount automatically, but you could end-up in the situation where you must do it manually.
To mount a partition:
First create a directory in /mnt (mkdir /mnt/my_new_drive) then use the mount command (mount /dev/source /mnt/my_new_drive) where /dev/source is the device (partition) you want to mount in your file system.

If you want to connect to a remote host, use the ssh command. The syntax is ssh <hostname>.

System management:

- ps - shows the current processes running (useful: ps -A shows up all processes)
In the list obtained by using ps command you will see a PID number (Process identification).

This number is required to stop a service or application. Use kill <PID> to stop a task.

- top - works somehow like the Task manager in Windows. It shows up the system resources, the processes running, average load, etc. Useful is top -d <delay> - sets up the refresh period. You can put any value from .1 (10 ms) to 100 (100 seconds) or even greater.

- uptime will display the system's uptime and the load average for that moment, 5 minutes and 15 minutes in the past.

Usually, the load average is calculated as the percent of system resources (processor, RAM, harddisk I/O, network load) used at that moment. 0.37 means that 37% was used. A greater value like 2.35 means that the system had to que some data because it should be 235% faster to compute all without problems. Anyhow, this can be different from distribution to distribution.

- free - will display information on system's memory

- ifconfig <interface_name> - view detailed information about your network interfaces; generally your ethernet network interface will be named eth0. You can also set up the network settings like ip address or so by using this command (see man ifconfig). If something goes wrong, you can also stop/start the interface by using ifconfig <interface_name> up/down

- passwd - enables you to change your password (passwd own_user or others if you are logged in as root)

- useradd - enables to add a new user (see man useradd)

Anywhere you are, you cand use the TAB key to autocomplete a filename or command. This will be usefull when getting used to the commands available. You can also hit up arrow and down arrow to scroll through the history of the commands you entered.
You can also use multiple command on one line. Let's say you want to create 3 directories at once. The syntax is mkdir dir1 ; mkdir dir2 ; mkdir dir3.
Another useful thing is the pipe command. You can get a command output through another. Eg: man mkdir | tail will display the last lines in the manual pages of the mkdir command.

If at anytime you are asked for the root account (the super-administrator of the system) you can login in temporary with it by using the su command. You should also include -l (su -l) parameter to switch the home folder and available commands too. Note that you will be prompted for a password too.

To exit the shell type exit or logout.



Subscribe now via RSS feed and get all the new tutorials

written by satyen bhama , July 17, 2007

How do u find out the maximun Segment Size (MSS), how it is related to MTU.
written by Mihai Dobos , July 19, 2007

Hello

To see the MSS and MTU values, get an utility called iperf. In Fedora, type 'yum install iperf' (logged on as root). After installing it, you can run it to check the network performance. This is an example output:

[root@LinuxSrv psybnc]# iperf -m -c 192.168.0.100
connect failed: Connection refused
write1 failed: Broken pipe
write2 failed: Broken pipe
------------------------------------------------------------
Client connecting to 192.168.0.100, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 3] local 0.0.0.0 port 56715 connected with 192.168.0.100 port 5001
[ 3] 0.0- 0.0 sec 0.00 Bytes 0.00 bits/sec
WARNING: Path MTU Discovery may not be enabled.
[ 3] MSS size 524 bytes (MTU 576 bytes, minimum)


The MTU and MSS are related depending on the packet state. In worst case when the headers are full (both IP and TCP maximum sized), MSS = MTU - 60 - 60 = MTU - 120. Best case is when MSS = MTU - 40.

Read more on this in RFC 879 - TCP maximum segment size and related topics

http://www.faqs.org/rfcs/rfc879

Hope this was useful.

Best regards.
written by Senthil , September 14, 2007

What is means in sed command using linux? Explain with Example.
written by Mihai Dobos , September 15, 2007

Hello

The sed command is used to edit a string of text; it will process input stream (a file or a pipe).

Run the command "man sed" to see all the details on it.

Mihai D.
written by Kanwar Singh , June 09, 2008

I have created macro on the linux server which convert word to pdf file. When i use the system cammand on the linux server it works fine.

But when i use same cammand from the php script to run that macro it does not work.

Basic shell cammands are working like ls,whoami etc.

Please me know what should i do to run macro throgh php shell script?

Thanks
written by Vijaykumar.d , June 14, 2008

IAM FRESHER IN LINUX .KINDLY FORWARD BASIC LINUX COMMANDS AND LINUX RELEATED TO MY MAIL ID.
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it

Do you need more help? Ask now!
 

busy
Last Updated ( Saturday, 23 June 2007 )