Sunday, July 14, 2013

Most Useful and handy Linux / Unix commands


pwd
It Prints the working directory, i.e., display the name of my current directory on the screen.

hostname
It Prints the name of the local host (the machine on which I am working). Use netconf (as root) to change the name of the machine.

whoami
Print my 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.

date
Print the operating system current date, time and timezone. For an ISO standard format,

time
Determine the amount of time that it takes for a process to complete + other process accounting. Don't confuse it with the date
command (see previous entry). E.g. I can find out how long it takes to display a directory content using: time ls. Or I can test the
time function with time sleep 10.

clock
hwclock
(two commands, use either). Obtain date/time from the computer hardware (real time, battery−powered) clock. You can also use one
of this commands to set the hardware clock, but setclock may be simplier (see 2 commands above). Example: hwclock
−−systohc −−utc sets the hardware clock (in UTC) from the system clock.

who
Determine the users logged on the machine.
 
w
Determine who is logged on the system, find out what they are doing, their processor ussage, etc. Handy security command.

rwho −a
(=remote who) Determine users logged on other computers on your network. The rwho service must be enabled for this command to
run. If it isn't, run setup (RedHat specific) as root to enable "rwho".

finger user_name
System info about a user. Try: finger root . One can use finger with any networked computer that exposes the finger service
to the world, e.g., I can do (try): finger @finger.kernel.org

last
Show listing of users last logged−in on your system. Really good idea to check it from time to time as a security measure on your
system.

lastb
("=last bad") Show the last bad (unsuccessful) login attempts on my system. It did not work on my system, so got it started with:

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 screenful. To see what another user was doing on your system, login as "root" and inspect his/her "history". The history is
kept in the file .bash_history in the user home directory (so yes, it can be modified or erased).

uptime
Show the amount of time since the last reboot.

ps
(="print status" or "process status") List the processes currently run by the current user.

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

top
Keep listing the currently running processes on my computer, sorted by cpu usage (top processes first). Press Ctrl+c when done.

gtop
ktop
(in X terminal) Two GUI choices for top. My favourite is gtop (comes with gnome). In KDE, ktop is also available from the
"K"menu under "System"−"Task Manager".

uname −a
(= "Unix name" with option "all") Info on your (local) server. I can also use guname (in X−window terminal) to display the info more
nicely.

free
Memory info (in kilobytes). "Shared" memory is the memory that can be shared between processes (e.g., executable code is "shared").
"Buffered" and "cashed" memory is the part that keeps parts of recently accessed files−−it can be shrunk if more memory is needed by
processes.

cat /etc/issue
Check what distribution you are using. You can put your own message in this text file−−it's displayed on login. It is more common to
put your site−specific login message to the file /etc/motd ("motd"="message of the day").

df −h
(=disk free) Print disk info about all the filesystems (in human−readable form).

du / −bh | more
(=disk usage) Print detailed disk usage for each subdirectory starting at the "/" (root) directory (in human legible form).
 
cat /proc/cpuinfo
Cpu info−−it shows the content of the file cpuinfo. Note that the files in the /proc directory are not real files−−they are hooks to
look at information available to the kernel.

cat /proc/interrupts
List the interrupts in use. You May need to find out before setting up new hardware.

cat /proc/version
Linux version and other info.

cat /proc/filesystems
Show the types of filesystems currently in use.

cat /etc/printcap |more
Show the setup of printers.

lsmod
(= "list modules". As root. Use /sbin/lsmod to execute this command when you are a non−root user.) Show the kernel modules
currently loaded.

set|more
Show the current user environment (in full). Normally too much to bother.

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 (see the previous command).

dmesg | less
Print kernel messages (the content of the so−called kernel ring buffer). Press "q" to quit "less". Use less /var/log/dmesg to see
what "dmesg" dumped into this file right after the last system bootup.

chage −l my_login_name
See my password expiry information.

quota
See my disk quota (the limits of disk usage).

sar
View information extracted the system activity log file (/var/log/sarxx where xx is the current day number). sar can extract many
kinds of system statistics including CPU load averages, i/o statistics, and network trafic statistics for the current day and (usually)
several days backs.
 

No comments: