≡ Menu

Some Useful Linux Shell Commands

Shell is a program that connects users with the operating system in this case the kernel (core operating system), generally provides a shell prompt as the user interface, where users had fed the desired commands in the form of an internal shell command (internal command), or command execution of a program file (external command), but it allows the user formulate a set of shell commands on one or more files to be executed as a program.

Unlike other operating systems that only provide 1 or 2 shell, Unix family of operating systems such as Linux until recently complemented by the many shell with a collection of commands that very much, allowing the user to choose the shell where the most good to help get the job done, or can be Also moving from one shell to another shell that easily,

If you are new to shell (SSH), below are some commands to get you started. A full list of shell commands can be found here http://www.oreillynet.com/linux/cmd/

Some useful commands are:

cd /home/
Will change directory to the /home directory

This shows basic information such as uptime, cpu usage, memory usage and processes running.

List all files in a directory.

ls -al
List all files plus hidden files.

ls -alh
List all files and hidden files and display the file size in an easier format.

ps -aux
Show all processes running.

netstat -natp
Show all active tcp connections to your server.

netstat -naup
Show all active udp connections to your server.

tail filename
Show the end contents of a file. This is good for viewing last entries to log files.

Show who is logged into shell.

Show a list of all accesses to the server ftp and shell.

shows your current position in the filesystem

locate expression
Will find all files named with ‘expression’

find . -type f -exec fgrep -li happy {} ;
Will list all files in the current directory that contain the word ‘happy’

chown username.group file.txt
Will change the ownership of file.txt to user ‘username and group ‘group’

chmod 755 file.cgi
Will change the permissions on file.cgi

cp file.txt file2.txt
Copies file.txt to file2.txt

rm file.txt
Deletes file.txt

List the users logged in on the machine. —

rwho -a
List all users logged in on your network. The rwho service must be enabled for this command to work.

finger user_name
System info about a user. Try: finger root last. This lists the users last logged-in on your system.

history | more
Show the last (1000 or so) commands executed from the command line on the current account. The | more causes the display to stop after each screen fill.

Print working directory, i.e. display the name of your current directory on the screen.

Print the name of the local host (the machine on which you are working).

Print your login name.

id username
Print user id (uid) and his/her group id (gid), effective id (if different than the real id) and the supplementary groups.

Print or change the operating system date and time. E.g., change the date and time to 2000-12-31 23:57 using this command

date 123123572000
To set the hardware clock from the system clock, use the command (as root)


Determine the amount of time that it takes for a process to complete+ other info. Don’t confuse it with date command. For e.g. we can find out how long it takes to display a directory content using time ls

Amount of time since the last reboot

List the processes that are have been run by the current user.

ps aux | more
List all the processes currently running, even those without the controlling terminal, together with the name of the user that owns each process.

Keep listing the currently running processes, sorted by cpu usage (top users first).

uname -a
Info on your server.

Memory info (in kilobytes).

df -h
Print disk info about all the file systems in a human-readable form.

du / -bh | more
Print detailed disk usage for each subdirectory starting at root (in a human readable form).

(as root. Use /sbin/lsmod to execute this command when you are a non-root user.) Show the kernel modules currently loaded.

Show the current user environment.

echo $PATH
Show the content of the environment variable PATH. This command can be used to show other environment variables as well. Use set to see the full environment.

dmesg | less
Print kernel messages (the current content of the so-called kernel ring buffer). Press q to quit less. Use less /var/log/dmesg to see what dmesg dumped into the file right after bootup. – only works on dedciated systems

Commands for Process control
Display the list of currently running processes with their process IDs (PID) numbers. Use ps aux to see all processes currently running on your system (also those of other users or without a controlling terminal),
each with the name of the owner. Use top to keep listing the processes currently running.

PID Bring a background or stopped process to the foreground.

PID Send the process to the background. This is the opposite of fg. The same can be accomplished with Ctrl z

any_command &
Run any command in the background (the symbol means run the command in the background?).

kill PID
Force a process shutdown. First determine the PID of the process to kill using ps.

killall -9 program_name
Kill program(s) by name.

(in an xwindow terminal) Kill a GUI-based program with mouse. (Point with your mouse cursor at the window of the process you want to kill and click.)

(as root) Check and control the printer(s). Type ??? to see the list of available commands.

Show the content of the printer queue.

lprm job_number
Remove a printing job job_number from the queue.

nice program_name
Run program_name adjusting its priority. Since the priority is not specified in this example, it will be adjusted by 10 (the process will run slower), from the default value (usually 0). The lower the number (of niceness to other users on the system), the higher the priority. The priority value may be in the range -20 to 19. Only root may specify negative values. Use top to display the priorities of the running processes.

renice -1 PID
(as root) Change the priority of a running process to -1. Normal users can only adjust processes they own, and only up from the current value (make them run slower).

Logs you out of shell.

I hope this Linux Shell Commands can be useful for you all

{ 1 comment… add one }
  • dhidayat June 27, 2011, 2:37 pm

    nice post pakcik.. “usefull” pizan banget. little2 we have to learn more about cli in linux..

Leave a Comment