Wednesday, September 26, 2007

Top 25 Linux Commands !

Perhaps your company is just switching to Linux, to save on costs. Or, maybe you’re starting University, and you have no idea how to get around the Linux Systems they’ve just installed. Or if you’re like me, you’re curious about how Linux works, and you have it installed at home. Either way, if you are interested in working with the terminal, and using common admin commands, this is the right place for you. Below are the top 10 commands for the Absolute Newbie administrators. Remember, if this is the first time you’ve used one of these commands, you can simply type “man” then the name of the program to get help on each of these commands.

#1. hostname

Prints the name of the local host that you are currently working on. Use netconf to change the name of the machine.

#2. whoami

This prints your login name on the screen. This can be extremely useful if you switch between a user and root.

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

#4. date
Print or change the operating system date and time. E.g., I could change the date and time to 2000-12-31 23:57 using this command:
date 123123572000
To set the hardware (BIOS) clock from the system (Linux) clock, use the command (as root) setclock <- Do not use this for evil.

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

I used this command all the time in University. It’s really useful for checking to see how efficient your algorithms are.

#6. who
Determine the users logged on the machine.

#7. rwho -a
(=remote who) Determine all users logged on your network. The rwho service must be enabled for this command to run. If it isn’t, run setup as root to enable “rwho”.

#8. finger user_name
System info about a user. Try: finger root

Believe me, as an administrator, you will use this one all of the time.

#9. last
Show listing of users last logged-in on your system.

#10. 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.

Not only can you press the up button, but you can list the history in this manner. This is extremely useful, if you have to type in complicated commands that require long directory listings.

#11. uptime
Show the amount of time since the last reboot.

#12. ps
(=print status) List the processes currently run by the current user.

This is like the task manager for windows, but more ghetto. Although, you do have more control.

#13. 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.

#14. top
Keep listing the currently running processes, sorted by cpu usage (top users first). In KDE, you can get GUI-based Ktop from “K”menu under “System”-”Task Manager” (or by executing “ktop” in an X-terminal).

#15. 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.

#16. free
Memory info (in kilobytes).

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

This command is so useful. I found it really difficult to tell in my linux systems how much memory I had left. This was a life saver.

#18. du / -bh | more
(=disk usage) Print detailed disk usage for each subdirectory starting at the “/” (root) directory (in human legible form).

#19. cat /proc/cpuinfo
Cpu info-it show 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.

#20. cat /proc/interrupts
List the interrupts in use.

#21. cat /proc/version
Linux version and other info.

Very useful if you are updating or recompiling your kernel.

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

#23. cat /etc/printcap
Show the setup of printers.

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

#25. 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.


Zack said...

I think pwd should be there purely for the fact that someone new to linux could get confused with the filesystem quite easily

Erin said...

Ditto. Without pwd, all our base would belong to null.

David said...

Don't forget lsof - very handy for viewing the files that are currently opened. If your system is under a heavy load, this can be useful for determining which processes are opening lots of files.

It's also useful to learn how to pipe commands (ps -auwx | grep [username] ) to produce quick reports about the system.

Uncle DirtNap said...

I've been a senior unix sysadmin for over 10 years, and I always wonder who it is who writes these lists, and for whom they are intended.

hostname is the #1 command? It is unlikely you will need to change a machine's hostname more than once a year; it's very likely that the current hostname is part of the default system prompt.

cat /proc/interrupts is on the list, but not grep? That's not even a command.

See, in every list of this type I see get dugg, which must be 3 a week, the author fails to realize that the meat of the shell is compound commands -- loops, pipelines, etc.

Pretending for a minute that sed and awk are programming environments and don't count as commands, here are 10 that are infinitely more useful than whoami:

man: You're right about man -- man is the most important command to know (especially man -k)

grep: Global Regular Expression Print. Searches a file for a pattern (or absence of a pattern) and returns the lines that [don't] match.

cut: Since I was going to ignore awk, you need some way to get at columnar data.

find: Searches one or more file systems for objects matching a list of characteristics.

xargs: pass a list of arguments to a single command, one after the other.

loop built-ins: The for, each and while commands built in to most shells aren't just for scripting, they're great for one-off commands.

top: This is another one you definitely got right -- just know that, on a resource starved system (where you might want to run top,) top can be a bit of a hog.

ps: ...and your final correct answer -- I don't know how ps could be considered ghetto, though. Again, the "ghetto"ness off text based tools is a misassumption of people who don't use or understand compound commands.

test: test conditions and return true or false -- again, if you're really using the shell, and you're really doing enterprise work, you'll use this in ad-hoc commands every day.

ls: Seriously. You got ps, but ls is even more important (lists directory contents...)

...and that's to say nothing of sed, awk, nc, mknode, etc.

pshaw said...

This list leans heavily towards system administration commands. You could easily write a "Top 25 Linux Commands" list for software development or "Top 25 Linux Commands" for text processing, or any of the other focuses of Linux use.

For starts, type the word "yes" into your console and let me know when the program finishes.

Ryne said...

Although this isn't a big deal... if you're going to pipe into something for readability, why wouldn't you use less?

in Linux, less is more ;) said...

Sharing your downloaded ubuntu softwares!