Solution Spotlight TOP LINUX COMMANDS TO BE...

27
Solution Spotlight TOP LINUX COMMANDS TO BE AWARE OF

Transcript of Solution Spotlight TOP LINUX COMMANDS TO BE...

Solution Spotlight

TOP LINUX COMMANDS TO BE AWARE OF

PA G E 2 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

n many cases, commands can expedite a user experience tremendously. This e-guide from SearchDataCenter.com pro-vides readers with crucial commands that

can facilitate both Unix and Linux system daily tasks. Providing the top 50 Unix commands as well as some lesser known but highly useful Linux commands, this guide will also address the differences between Unix and Linux systems.

I

PA G E 3 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

TWO LINUX AND UNIX COMMANDS YOU MIGHT NOT KNOW YOU NEED

What are some lesser known, but highly useful Linux and Unix commands, and what do they do?

Throughout my time as a system administrator, I’ve noticed that a hand-ful of commands are utilized disproportionately regularly, compared to the total number of commands available to the Linux administrator. For example, chmod, ls, mkdir and |more are a few commands that the typical Linux admin-istrator would be hard pressed to not invoke during the execution of his daily duties. In terms of “lesser known, but highly useful” commands, I would argue that these are really specific to every admin’s situation. So I can really only speak to a couple of commands that come to mind:

watch -n1 --difference “echo “Uptime”; uptime; echo \n ; ps -eo pcpu,pid,args | sort -k 1 -r |grep -v watch | head -10; echo “\n” ; tail /var/log/cron| grep check_load”

PA G E 4 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

This command allows the system administrator to conduct real time moni-toring of the local system within the command line. The output is similar to what the Windows administrator would see within the Task Manager. So the focus within this command revolves around the percentage of CPU an appli-cation is consuming, the application’s process ID and the command utilized to invoke the application.

history|awk ‘{print $2}’ |awk ‘{print $1}’ | sort | uniq -c | sort -rn | head -10

This command allows the system administrator to view the most used com-mands on whatever machine he is on at the time of use. There are similar com-mands that allow the administrator to view the most utilized commands over an entire network, but I prefer to focus on this command because this allows the administrator to log in to his assigned box and view what commands have been utilized on that specific box. If the administrator notices any anomalies, he can infer that someone else was executing commands from his computer.

PA G E 5 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

TOP 50 UNIVERSAL UNIX COMMANDSKenneth Milberg

Several years ago, I wrote a tip introducing the top Linux commands and utili-ties and also contributed to TechTarget’s effort identifying and describing the commands. During this go-around, we’ll do the same with Unix. Some of you not as familiar with Unix, might ask the question, “isn’t Unix and Linux basically the same thing?” The short answer is, “No.”

DIFFERENTIATING UNIX FROM LINUX: SOME HISTORY

Let’s briefly outline the fundamental differences. We’ll start with Linux. Linux roots trace back to 1983, when Richard Stallman started the GNU project. The goal was to create a free Unix-like system. The GNU General Public License (GPL) was also created by Stallman. In 1987, Andrew Tanenbaum released MINIX, a Unix-like system, which unfortunately was not well adapted to the 32-bit features of the Intel 386 architecture and lacked a fully-functioning ker-nel. This spawned Linux in 1991. Linus Torvalds actually wrote the program on a 386 processor using the GNU C compiler on MINIX.

PA G E 6 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

The roots of Unix go back much further, into the 1960s, when AT&T’s Bell Labs partnered with MIT and GE to develop a multi-user operating system called Multics. Dennis Ritchie and Ken Thompson worked on this project up until the time that AT&T withdrew from it. This OS was developed in an at-tempt to port a computer game to a DEC PDP-7 computer. This version was named Unics, which eventually evolved into Unix. Unix would evolve into two branches, BSD and System V. The BSD model, developed by the University of California Berkeley – was considered more academic while System V was perceived as being more commercial. Interestingly enough, the original Sun OS was based on BSD but the pendulum swung the other way with the release of Solaris V5, where it was based on System V, release V. Today, there are three popular Unix flavors that dominant this market – HP-UX, AIX and Solaris. So-laris and HP-UX are System V based, while AIX is an interesting Hybrid of both. An example of this is printing. AIX offers lpr (BSD version), lp (System V) and even their own propriety way of printing using qprt. In many ways this is very typical of AIX, though all of these flavors have many proprietary differences, from kernel, monitoring and tuning commands, to networking configuration, virtualization and other processes.

Perhaps the most fundamental difference between Unix and Linux is that

PA G E 7 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

the bulk of the work on Linux (though Red Hat or Novell might dispute this) is really performed by the community: the thousands of programmers around the world that use Linux and send in their suggested improvements. Without a doubt, the top companies that commercially sell Linux distributions contrib-ute to the development of the kernel, while also adding added-value software that is shipped with the OS, but the kernel itself is maintained by Linus and his team. For all intents and purposes - Torvalds (who owns the Linux trademark) remains the ultimate authority on the new code which is incorporated into the standard Linux kernel This is not the case with Unix – each of the hardware vendors pretty much do there own thing with their versions of Unix – Solaris, HP-UX and AIX, though interestingly enough, Novell owns the actual rights to Unix.

TOP 50 UNIX COMMANDS

Disclaimer: The 50 Unix commands presented here will only discuss com-mands that are available on all flavors. A following article will discuss some fundamental differences between these flavors and also detail some of the command-line differences on how to administrate and configure essential processes on each system. Why is it important to do this? There are literally

PA G E 8 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

thousands of commands that a UNIX administrator has at their disposal. The reality is that even the most advanced administrators will only use a finite number of tools and utilities on an ongoing basis. They also try to master these specific commands and utilities that help them become better administrators. Are some of the commands similar to the Linux in our original top 50? Abso-lutely, but there are enough differences to warrant a new revised list as well as a revised numbering order. We’ll also add some content to the changes in that original list as appropriate to Unix. A small sampling of some of the commands we’ll see here, which you won’t find on the original list, include – ps, w, who, uname, id. Some of the commands you’ll find on both lists include, cron, vmstat, vi, netstat and find.

1. ALIAS

Alias allows you to substitute a small or more familiar name in place of a long string.Example: This usage will tailor the du command to use 1k units:# alias du=du -k

PA G E 9 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

2. AWK

Awk searches for patterns in a file and processes them. It enables a program-mer to write small programs in the form of statements to make changes in text files when certain patterns appear or extract data from those files. This command simplifies a process historically done in C or Pascal languages. (Learn more in this Linux shell scripting tutorial on awk.)Example: This will count the number of lines in the file – similar to wc –l# awk ‘END{print NR}’

3. CAT

Abbreviated from the word “concatenate,” which means to link things to-gether, cat is used in Unix to link file contents and output them for viewing or printing. It is also used to display a file.Example: This will view the /etc/hosts file.# cat /etc/hosts

4. CD

The cd command sets the working directory of a process. Example: This usage will change the directory to your home directory,

PA G E 1 0 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

assuming your HOME variable is defined# cd $HOME

5. CHMOD

Chmod is a utility that changes the permission of a file. Example: This will change the permission of the file called newfile to read, write and execute (rwx) for owner, group and other.# chmod 777 newfile

6. CHOWN

A utility used to change file ownership. Example: This usage will change the ownership of the file called newfile to frank.# chown frank newfile

7. CP

The cp command is used to copy files. Example: This usage will copy the file testdb to another directory on the system.

PA G E 1 1 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

# cp /tmp/testdb /home/frank/testdb

8. CPIO

This command is used to copy and move around files and directories. It also backs up empty directories which restores files from an archive or creates an archive. Example: This will copy all files and directories in the current directory to another directory called /user/newfiles.# find ./ -depth | cpio –pdmv /usr/newfiles

9. CRONTAB

Crontab is used for manipulating cron – used to schedule tasks.Example: This usage displays your crontab file:# crontab -l

10. DF

The df command reports filesystem disk space usage.Example: This example displays disk space in kilobytes.# df -k

PA G E 1 2 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

11. DU

The du command reports back the sizes of directory trees. Example: This command reports summarizes the file size from the direc-tory which you are running the command from.# du –s

12. ENV

The env command displays information about your current environment.Example: This command displays all your environment variables# env

13. ECHO

This command lets you echo a string variable to standard output.Example: This reports back “Hello World”# echo Hello World

14. ENABLE

Enables or disables a printer.Example: This enables printer1.

PA G E 1 3 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

# enable printer1

15. EXIT

Allows you to exit from a program, shell or UNIX network.Example: This exits the shell.# exit

16. EXPORT

Export sets the value of a variable so it is visible to all sub-processes that belong to the current shell.Example: This command exports the TERM variable.# TERM=vt220 ; export $TERM

17. EXPORTFS

This command maintains a list of NFS exported file systems.Example: This usage exports all directories# exportfs -a

PA G E 1 4 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

18. FIND

Find searches the directory tree rooted at each given file name by evaluat-ing the given expression from left to right, according to the rules of pre-cedence (see section OPERATORS), until the outcome is known (the left hand side is false for and operations, true for or), at which point find moves on to the next file name. Example: This command searches for all the files and directories in a given directory and sends them to standard output.# find ./ -depth

19. FTP

ftp allows for the copying of files back and forth on different host machines.Example: This command starts up ftp# ftp

20. GREP

Grep is a command used for searching one or more files for a given char-acter string or pattern. It can also be used to replace the character string with another one.

PA G E 1 5 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

Example: this usage searches for instances of hello within the file text.txt# grep hello text.txt

21. GZIP

gzip is a compression utility designed to be a replacement for compress. Its main advantages over compress are much better compression and freedom from patented algorithms. It has been adopted by the GNU project and is now relatively popular on the Internet. gzip was written by Jean-loup Gailly and Mark Adler for the decompression code. Example: This usage compresses the file and renames it to test2 in gzip format. gunzip is used to uncompress a gzip file.# gzip -c testfile > test2.gz

22. ID

This command prints out real and effective UIDs and GIDs. Example: This usage shows all the uids and gids which show in your /etc/passwd.# id

PA G E 1 6 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

23. IFCONFIG

ifconfig checks a network interface configuration. It can be used, for ex-ample, to verify a user’s configuration if the user’s system has been recently configured or if the user’s system cannot reach the remote host while other systems on the same network can.Example: This usage shows all the adapter information.# ifconfig –a

24. IFUP

Starts up a network interface.Example: This usage brings up the interface en0# ifup en0

25. IFDOWN

Shuts down the network interface.Example: This usage brings down all interfaces which are up.# ifdown -a

PA G E 1 7 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

26. HEAD

This outputs the first part of a fileExample: This usage displays the first ten lines in the /etc/hosts file.# head -10 /etc/hosts

27. LAST

The last command shows the last users who logged into the system.Example: This usage lists out the shutdown times and run-level changes# last -x

28. LN

The ln command establishes links between files.Example: This usage establishes a symbolic link between two files.# ln -s sourcefile newfile

29. LS

The ls command shows information about files. With it, system adminis-trators can list the contents of a directory in order to determine when the configurations files were last edited. There are many subcommands under

PA G E 1 8 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

ls, such as ls-r, which can reverse the order in which files are displayed. (The ls command is also discussed in this tip on troubleshooting tools.) Example: This usage shows a long listing of file information in the data directory.# ls –l data

30. MAN

Short for “manual,” man unveils information about commands and a key-word search mechanism for needed commands. (The man command is also discussed in this tip on troubleshooting tools.)Example: This usage prints out information on the tar command# man tar

31. MV

This command moves a file to a different directory or filesystem.Example: This usage moves the file test to the /tmp directory# mv test /tmp

PA G E 1 9 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

32. NETSTAT

The netstat command shows the network status by symbolically display-ing the contents of various network-related data structures. There are a number of output formats, depending on the options for the information presented.Example: This usage shows the routing table.# netstat –r

33. PING

The ping command (named after the sound of an active sonar system) sends echo requests to the host you specify on the command line, and lists the responses received their round trip time. When you terminate ping (probably by hitting control-C) it summarizes the results, giving the av-erage round trip time and the percent packet loss. This command is used constantly to determine whether there is a problem with the network con-nection between two hosts.Example: This usage sends echo requests to hosta.# ping hosta

PA G E 2 0 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

34. PS

The ps command reports back process status. There are two ways that this is used – the System V way and the Berkeley method. The Berkeley method does not use the dash (-) before flags.Example: This usage reports pack process info using the System V method# ps –ef

35. PWD

pwd is short for print working directory. The pwd command displays the name of the current working directory.Example: This usage reports back the directory you are currently in# pwd

36. RSYNC

rsync is focused on synching data from one disk location to another. It was created by Andrew Tridgell, one of Samba’s core team. Example: This usage will transfer all files matching the pattern *.d from the current directory to the directory data on the machine hosta. (Learn more from this tip on Rsync and Amanda

PA G E 2 1 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

# rsync *.d hosta:data/

37. RM

The rm command is used to remove a file or a group of files. Example: This usage will prompt the user to make sure they want to delete the files in the directory before doing so# rm –i *

38. SED

sed (streams editor) isn’t really a true text editor or text processor. Instead, it is used to filter text, i.e., it takes text input and performs some operation (or set of operations) on it and outputs the modified text. Sed is typically used for extracting part of a file using pattern matching or substituting multiple occurrences of a string within a file. Example: This usage inserts a blank line below every line which matches “test”.# sed ‘/test/G’

PA G E 2 2 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

39. SHUTDOWN

Shutdown is a command that turns off the computer and can be combined with variables such as -h for halt or -r for reboot. Example: This usage reboots the box in AIX. Because the flags are a bit dif-ferent between Unix flavors – do a man before running shutdown on your flavor.# shutdown -Fr

40. SUDO

Sudo (superuser do) allows a system administrator to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while logging the commands and arguments. Example: Assuming the user that is using sudo has already been configured to do so, this command allows him to run the adduser command as if he were root.$ sudo -u root adduser testuser

41. SSH

Ssh is used for secure network connections and tunneling of TCP services.

PA G E 2 3 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

OpenSSH is one open source SSH version. (See these examples of how to use ssh with Unix).Example: This usage connects user ken to hostb.com# ssh -l ken hostb.com

42. TAR

The tar program provides the ability to create tar archives, as well as vari-ous other kinds of manipulation. For example, you can use tar on previously created archives to extract files, store additional files, or update or list files. Initially, tar archives were used to store files on magnetic tape. The name “tar” comes from this use; it stands for “tape archiver.” Despite the utility’s name, tar can direct its output to available devices, files, or other programs. Tar may even access remote devices or files. Example: This usage creates a tar archive to tape device st0 – with the con-tents of /home:# tar -cvf /dev/st0 /home

43. TAIL

The tail command outputs the last part of a file.

PA G E 2 4 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

Example: This usage displays the last ten lines of the /etc/hosts file.# tail -10 /etc/hosts

44. TRACEROUTE

traceroute determines a route to the host and is very useful for distinguish-ing network/router issues. If the domain does not work or is not available you can traceroute an IP. Example: This usage runs a traceroute to an inaccessible domain to try to determine the cause of the problem.# traceroute hostc.org

45. UNAME

uname prints system name and other related information about your system.Example: This usage displays a long-listing of system information.# uname -a

46. VI

vi is a screen-based editor preferred by the vast majority of Unix users.

PA G E 2 5 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

Example: This usage brings up vi in editor mode - to edit the /etc/hosts file.# vi /etc/hostsLearn more in this tutorial: Mastering the vi editor

47. VMSTAT

The vmstat command is used to get a snapshot of everything going on in the system - helping systems administrators determine whether the bottleneck is CPU, memory or I/O. Run this command to get virtual memory statistics. Example: This usage starts up vmstat and runs it every two seconds for ten iterations.# vmstat 2 10

48. W

The w command prints a summary of current system and user information, while also letting you know who is logged in to the system and what they are doing.Example: this usage prints out a short version of information.# w –s

PA G E 2 6 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

49. WHO

The who command displays the users who are logged on to the system. Example: This usage lists all the available output of the who command for each user.# who –a

50. WHOAMI

The whoami command displays who the user is that you are logged on as. This is very useful for those of you that have different logins. Example: This usage displays the name of the user that you are presently logged in as.# whoami

PA G E 2 7 O F 2 7 S P O N S O R E D B Y

Home

Two Linux and Unix commands you might not know you need

Top 50 universal Unix commands

SOLUTION SPOTLIGHT: TOP LINUX COMMANDS TO BE AWARE OF

FREE RESOURCES FOR TECHNOLOGY PROFESSIONALSTechTarget publishes targeted technology media that address your need for information and resources for researching prod-ucts, developing strategy and making cost-effective purchase decisions. Our network of technology-specific Web sites gives you access to industry experts, independent content and analy-sis and the Web’s largest library of vendor-provided white pa-pers, webcasts, podcasts, videos, virtual trade shows, research

reports and more —drawing on the rich R&D resources of technology providers to address market trends, challenges and solutions. Our live events and virtual seminars give you ac-cess to vendor neutral, expert commentary and advice on the issues and challenges you face daily. Our social community IT Knowledge Exchange allows you to share real world information in real time with peers and experts.

WHAT MAKES TECHTARGET UNIQUE?TechTarget is squarely focused on the enterprise IT space. Our team of editors and net-work of industry experts provide the richest, most relevant content to IT professionals and management. We leverage the immediacy of the Web, the networking and face-to-face op-portunities of events and virtual events, and the ability to interact with peers—all to create compelling and actionable information for enterprise IT professionals across all industries and markets.