Linux Server Commands
Linux / Unix Command: uname
* -a, –all
print all information, in the following order:
* -s, –kernel-name
print the kernel name
* -n, –nodename
print the network node hostname
* -r, –kernel-release
print the kernel release
* -v, –kernel-version
print the kernel version
* -m, –machine
print the machine hardware name
* –p, –processor
print the processor type
* -i, –hardware-platform
print the hardware platform
* -o, –operating-system
print the operating system
* uname -m returns the machine architecture i.e. i386 for Intel/AMD platforms.
* uname -p returns the processor architecture i.e. i686 for Intel/AMD platforms.
* uname -i (if implemented) returns the actual hardware platform i.e model number or such like.
cat /etc/issue = returns Linux release
To Find Out How Long The System Has Been Running :
uptime
Sample outputs:
21:54:11 up 13 days, 4:29, 1 user, load average: 0.21, 0.21, 0.12
The uptime command gives a one line display of the following information.
The current time (21:54:11) The uptime command gives a one line display of the following information
How long the system has been running (up 13 days)
How many users are currently logged on (1 user)
The system load averages for the past 1, 5, and 15 minutes (0.21, 0.21, 0.12)
Linux Set Date and Time From a Command Prompt :
Use the following syntax to set new data and time:
date –set=”STRING”
For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
date -s “2 OCT 2006 18:00:00″
or
date –set=”2 OCT 2006 18:00:00”
You can also simplify format using following syntax:
date +%Y%m%d -s “20081128”
Linux Set Time
To set time use the following syntax:
date +%T -s “10:13:13”
Where,
* 10: Hour (hh)
* 13: Minute (mm)
* 30: Second (ss)
Use %p locale’s equivalent of either AM or PM, enter:
date +%T%p -s “6:10:30AM”
date +%T%p -s “12:10:30PM”
Do check and sync hardware clock with:
hwclock –show
hwclock –systohc
clock
date
How many users are currently logged on Server :
w
This is the same information contained in the header line displayed by the w and top commands: (user).
Top provides an ongoing look at processor activity in real time.
top
Start top ignoring any idle or zombie processes
-H
Show all threads.
-b
Batch mode. Useful for sending output from top to other programs or to a file. In this mode,
top will not accept command line input. It runs until it produces the number of iterations requested
with the n option or until killed. Output is plain text suitable for display on a dumb terminal.
My Favorite updates every second
top -d 1
Batch mode. Useful for sending output from top to other programs or to a file. In this mode,
top will not accept command line input. It runs until it produces the number of iterations requested
with the n option or until killed. Output is plain text suitable for display on a dumb terminal.
Using Bash History
Before you begin typing your command, type ctrl-r. This will put you into history search mode
(actually, reverse incremental history search mode).
Now when you begin typing, the most recent command matching what you’ve typed so far will
appear on the line with a cursor at the start of the match.
(Try playing around with this feature; there are a few interesting behaviors in there.)
If you really are uncertain of the history or if you know you could be searching back through
many similar commands for one of particular interest, then you can use this more brute-force method.
Type the following command to get a list of all related commands with their history numbers:
history | grep -i “<search string>”
Once you’ve found the command you want, you can execute it specifically by its number using the
following built-in history expansion command:
<history number>
To clear bash history :
history -c
A common and convenient way of using ps to obtain much more complete information about the
processes currently on the system is to use the following :
ps -aux | less
An alternative set of options for viewing all the processes running on a system is :
ps -ef | less
The processes shown by ps can be limited to those belonging to any given user by piping
the output through grep, a filter that is used for searching text. For example, processes belonging
to a user with a username adam can be displayed with the following :
ps -ef | grep adam
The free command provides information about unused and used memory and swap space on
any computer running Linux or another Unix-like operating system.
The basic syntax of free is
free [options]
Several options are available to change the unit of display for free from its default kilobytes,
including -b for bytes, -m for megabytes and -g for gigabytes. Of these, -m is usually the most useful.
Thus, for example, to show all of the data in megabytes, the following would be used:
free -m -g for gigabytes
The -t option instructs free to additionally display a fourth line of data containing the totals
for physical memory and swap space.
This scrolling output can be terminated by simultaneously pressing the CONTROL and c keys.
Thus, for example, the following would provide new data every five seconds and display the
output in megabits:
free -ms 5
to display memory utilization every two seconds, the following would be used:
watch free
which highlights changes in output, and its -n option followed by the number one to increase the
frequency of reports to one per second as follows:
watch -n 1 -d free
More detailed information about total memory and current memory usage can be obtained by reading
the proc/meminfo file directly. This can be accomplished, for example, with the cat command
(which is commonly used to read text files) as follows:
cat /proc/meminfo