L Linux Command List Dunwoody College of Technology 11-1-11 Matthew Kerfoot An A-Z index of the Bash command line for Linux Page |2 Cd Changes the Directory Location: Syntax: cd [directory] cd../home/users/computerho pe The above example would go back one directory and then go into the home/users/computerhope directory. cd ../../ The above example would go back two directories. Cd Cd alone will move you into the home directory. Cal Display a calendar Location: /usr/bin/cal Syntax: cal [month] [year] cal Gives you the calendar for this month. Cal 12 2000 Gives you the calendar for December of 2000. cal 1 2011 displays the month of January, 2011. Rmdir Remove folder(s) Location:/bin/ Syntax: rmdir [option]…directory… rmdir /lib will delete the /lib directory rmdir c:\test /s remove the directory and all files in it. Rmdir c:\test –q will do a quiete deletion.(no questions asked.) Ls List information about file(s) Location: /bin/ls Syntax: ls [-a] [-A] [-b] [-c] [-C] [-d] [-f] [-F] [-g] [-i] [-l] [-L] [-m] [-o] [-p] [-q] [r] [-R] [-s] [-t] [-u] [-x] [pathnames] ls/ Lists the documents of your root directory ls */ Lists the contents of all sub directories. ls –laxo Lists files with permissions, shows hidden, displays in a column format, and doesn’t show the group. Man Help manual Location:/usr/bin/man Syntax: man [-] [-k keywords] topic man –k cal will seach for the keyword cal in all manuals. man mkdir lists help information on the mkdir command. man –k irc quickly searches for manuals containing irc within them. Mv Move or rename files or directories Location: /bin/mv Syntax: mv [-f] [-i] oldname newname mv oldname newname Will rename that file in that directory. mv –f oldname newname Will rename file without asking you. mv –I oldname newname Will prompt you before overwriting another file Pwd Print Working Directory Location:/bin/pwd Syntax: pwd [option] pwd Will display /etc in the prompt. man pwd Will display the manual for the pwd command. pwd –P Will print the working directory, without displaying all symlinks. pwd –L Use pwd from environment, even if it contains symlinks. Info Location: /usr/bin/info Syntax: info [option] . . . [menuiteam…] [-k] [-d] [-f] [-h] info info show the general manual for info readers info emacs start the emacs node from top-level dir info –show-options emacs Start at node with emacs’ command line options Who Print all usernames currently logged in Location: /usr/bin/who Syntax: who [option] . . . [file | arg1 arg2] who –r Cat Concatenate and print (display) the content of files Location:/bin/cat Syntax: cat filename [-n] [-b] [-u] [- Cp Copy one or more files to another location. Location:/bin/co Syntax: cp [OPTION]... SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... --targetdirectory=DIRECTORY SOURCE... cp file1.txt newdir Copies the file1.txt in the current directory to the newdir directory. cp *.txt newdir Copies all files ending in .txt into newdir directory. cp –r /home/hope.files/* /home/hope/files2 copies all the files, directories, and subdirectories in the files directory into the backup directory. Tar Tape Archiver Location: /bin/tar Syntax: tar c [ bBeEfFhiklnopPqvwX [ 0-7 ] ] [ Uptime Displays all the time information. Location: /usr/bin/uptime Syntax: uptime [-V] uptime –v will display the version information. uptime Will display details about how long your server has been up and running, and how many users are logged in, and system load averages for the past 1, 5, and 15 minutes. Man uptime Displays the manual for the uptime command. Free Display memory usage Location: /usr/bin/free Syntax: free [-b | -k | -m] [-o] [-s delay ] [-t] [-V] free –V Will display version information. free –s Will switch activates continuous polling delay. free –t Will switch display line containing the totals. free –b Will show space in bytes free –k Will display it in kilobytes. Vmstat Report virtual memory statistics Location: /usr/bin/vmstat Syntax: vmstat [-V] [-n] [delay [count]] vmstat Running vmstat command with no extra options would display information about memoty, swap, io, system, and CPU vmstat –V Prints version information onto screen. vmstat –d Prints disk statistics to the screen Id Print user and group id's Location: /usr/bin/id Syntax: id [-a] [-G] [-g] [-u] [user] info id Page |3 Will display the run-level of each user. who –b Will indicate the time and date of the last reboot who –s (Default) lists only the name, line, and time fields. s] [-v] cat file1.txt file2.txt > file3.txt reads file1.txt and file2.txt and combines those files to make file3.txt. cat food will display the cat file to the screen. cat eats bird > detailsat11 Join the files eat and bird into detailsat11. Whoami Print the current user id and name Location: /usr/bin/whoami Syntax: whoami [option] whoami will display the name of the current directory. If you are logged on as Root and type whoami it will say you are logged onto the root account. whoami –version Will output the version information and exit. whoami –help Displays the help and exit Head Output the first part of file(s) Location: /usr/bin/head Syntax: head [-number | -n number] filename. head -15 myfile.txt will display the first ten lines of myfile.txt head myfile.txt Will show the first 10 lines in myfile.txt head -n number Shows the number of lines you chose for it to display. su and/or sux Substitute user identity(become super user) Location: /bin/su Syntax: su [ - ] [username [arg] ] su – hope Login as the user hope, if she is logged in. su – hope This will pass the environment along unchanged as if the user actually logged in as the specified user. su hope arg Logs in as hope and additional arguments that need to be passed through the su command. Tail Output the last part of files Location: /usr/bin/tail Syntax: tail [+ number] [-l] [-b] [-c] [-r] [-f] [-c number | -n number] [file] tail myfile.txt The above example would list the last 10 (default) lines of the file myfile.txt. tail –f myfile.txt Displays the last 10 lines and then update the file as new lines are being added. This is a great command to watch log files or logs in real-time. tail –f access.log |grep 24.10.160.10 Allows you to watch the access.log foe any IP address of 24.10.160.10 block ] [ tarfile ] [ exclude-file ] {-I include-file | -C directory | file | file } tar r [ bBeEfFhiklnqvw [ 0-7 ] ] [ block ] {-I include-file | -C directory | file | file } tar t [ BefFhiklnqvX [ 0-7 ] ] [ tarfile ] [ exclude-file ] {-I includefile | file } ... tar u [ bBeEfFhiklnqvw [ 0-7 ] ] [ block ] [ tarfile ] file ... tar x [ BefFhiklmnopqvwX [ 0-7 ] ] [ tarfile ] [ exclude-file ] [ file ... ] Tar –cvwf file.tar myfile.txt Creates a tar named file.tar in the directory you are currently in. -xvwf myfile.tar Uncompress (untar) the myfile.txt file in the current directory. Tar –xvwzf myfile.tar.gz Uncompress the myfile.tar.gz file in the current directory. Gzip Compress or decompress named file(s) Location: /usr/bin/gzip Syntax: gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ... ] gunzip [ -acfhlLnNrtvV ] [-S suffix] [ name ... ] zcat [ -fhLV ] [ name ... ] bzip/bzip2 Compress or decompress named file(s) Location: /usr/bin/bzip2 Syntax: bzip2 [cdfkqstvuzVL123456789] [filenames. . .] bzip2 –f [filename] Forces overwrite of output files. bzip2 –t filname Check integrity of the specified files, but don’t decompress them. bzip2 –q filename suppress non-essential warning messages. Will still display I/O errors. Should give you access to the complete manual. id –g Print only effective group ID. id –G Prints all group IDs Shutdown Shutdown or restart linux Location: /sbin/shutdown Syntax: shutdown [-a][-t sec][krhnfFc][time][warning-message] shutdown 8:00 Shutdown computer at 8-oclock shutdown –t sec Tells init to wait sec seconds between sending processes the warning and the kill signal, before changing to another run-level. shutdown –h Halts after shutdown. Halt Reboot, poweroff – stop the Location: /sbin/halt Syntax: halt [-l] [-n] [-q] [-y] or halt [-n] [-w] [-d] [-f] [-i] [-p] [-h] reboot [-n] [-w] [-d] [f] [-i] poweroff [-n] [-w] [-d] [-f] [-i] [-h] halt Set the computer to a mode that enables a user to turn off the computer. halt –q Quick halt. No graceful shutdown required. halt –l Suppresses sending a message to the system log deamon, syslogd, about who executed halt. poweroff Stops the processor (if Page |4 you have the right permissions). Whatis Display manual page descriptions. Location: /usr/bin/whatis Syntax: whatis [-dlhV] [-r|-w] [-s section] [-m system[,…]] [-M path] [-L locale] [C file] name… whatis –d prints debugging information to the screen. whatis –M manpath –w ‘*’ | sort > manpath/whatis Produces an old style text whatis database from relative index database. whatis –V Will display the version information to the output of the monitor. Whereis Search the user's $path, man pages and source files for a program Location:/usr/bin/whereis Syntax: whereis [ -bmsu ] [ -BMS directory... -f ] filename ... whereis –b Searches only for binaries. whereis –m Searches only for manual sections. whereis –s Searches only for sources. Which Search the user's $path for a program file Location: /usr/bin/which Syntax: which [ filename ] ... which pearl Would locate the executable location of the pearl command which -a prints all matching executables in PATH, not just the first one. which() { declare –f |which – read-functions $@ } Will read shell function definitions from stdin, reporting matching ones on Less Display output one screen at a time Location: /usr/bin/less Syntax: less -? less --help less -V less --version less [[+]aBcCdeEfFgGiIJmMn NqQrRsSuUVwWX] [-b space] [-h lines] [-j line] [-k keyfile] [-{oO} logfile] [-p pattern] [-P prompt] [-t tag] [-T tagsfile] [-x tab,...] [-y lines] [-[z] lines] [+[+]cmd] [--] [filename]... less –j Displays the status column at the left edge of the screen. less –V Displays the version number of less. less table1 Will display the top of file table1 More Display output one screen at a time Location: /bin/more Syntax: more [-c] [-d] [-e] [-f] [-i] [l] [-n number] [-p command] [-r] [-s] [-t tagstring] [-u] [-w] [ -lines ] [ + linenumber ] [ +/ pattern ] [ file ... ] more –c Clear before displaying. Redraws the screen instead of scrolling for faster displays. more –e Exit immediately after writing the last line of the last file in the argument list. more –i Perform pattern matching in searches without regard to case. Grep Search file(s) for lines that match a given pattern Location: /usr/bin/grep Syntax: grep [options] PATTERN [FILE...] grep [options] [-e PATTERN | -f FILE] [FILE...] grep –a Processs a binary file as if it were text; this is equivalent to the— binary-files=text option grep –b Prints the byte offset within the input file before each line of the output. grep –V Prints the version number of grep to standard error. Kill Stop a process from running Location: /bin/kill Syntax: kill [-s] [-l] %pid kill –s Specify the signal to send. kill –l Write all values of signal supported ny the implementation. kill –pid You can specify a decimal integer which specifies a process or group of processes, or a job control ID that identifies a background process group to be signaled. Ln Make links between files Location: /bin/ln Syntax: ln [-f] [-n] [-s] existingfile newname ln –n Will not overwrite existing files. ln –s Makes it so that it does not create a symbolic link existing file – the file that you want to create a link to. ln –f Will link files without questioning the user, even if the mode of the target forbids writing. This is default in the standard input is not a terminal. Vi Text Editor Location: /usr/bin/vi Syntax: vi [ -| -s ] [-l] [-L] [-R] [ -r [ filename ] ] [-S] [-t tag] [-v] [-V] [-x] [-w] [-n ] [-C] [+command | -c command ] filename vi myfile.txt Will edit the file myfile.txt vi- | -s myfile.txt Suppress all interactive user feedback. this is useful when processing editor scripts vi –R myfile.txt Type Describe a command Location: a shell builtin Syntax: touch [-a] [-c] [-m] [-r ref_file | -t time ] file settime [ -f ref_file ] file touch newfile.txt Creates a file known as :newfile.txt”, if the file does not already exists. If the file already exists the accessed / modification time is updated for the file newfile.txt touch –a myfile.txt Ifconfig Configure a network interface Location: /sbin/ifconfig Syntax: ifconfig [-L] [-m] interface [create] [address_family] [address[/prefixlength] [dest_address]] [parameters] ifconfig interface destroy ifconfig -a [-L] [-d] [m] [-u] [address_family] ifconfig -l [-d] [-u] [address_family] ifconfig [-L] [-d] [-m] [-u] [-C] ifconfig add Another name for alias parameter. ifconfig –interface This parameter is a string of the form ‘ ‘ name unit”’ for example, ‘ ‘ en0”. ifconfig remove Another name for the – alias parameter. Alias Create an alias Location: a shell builtin Syntax: alias [name=['command']] alias home ‘cd public_html’ Sets home to type cd public_html alias this command by itself lists all the aliases we have created. alias ll alias ll=’ls –l’ Will show a long colored listing of all Page |5 stdout. readonly mode; the readonly flag is set, preventing accidental overwriting of the file. Will change the access time of the file. Do not write any diagnostic messages concerning this condition. settime myfile.txt Sets the file myfile.txt as the current time/date. Find Search for files that meet a desired criteria Location: /usr/bin/find Syntax: find path expressions find –name “MyCPrgram.c” Finds files using names, displays files and subdirectories. find –iname “MyCProgram.c” Finds files using name and ignoring case. find . –type -F –exec ls –s {} \; | sort –n –r |head -5 Finds the top 5 biggest files in the current directory and its subdirectories. Touch Change file timestamps Location: /usr/bin/touch Syntax: touch [option] . . . file . . . touch myfile.txt just updates the timestamp of the file to the computer’s current date and time. touch project.c will simulate an update to project.c touch myfile.txt –a changes only the access time. Ping Test a network connection Secure Shell client (remote login program). Sends ICMP ECHO_REQUEST packets to network hosts. Location: /bin/ping Syntax: ping -s [-d] [-l] [-L] [-n] [r] [-R] [-v] [ -i interface_address ] [-I interval] [-t ttl] host [packetsize] [count] ping –I 0.1 IP Decreases ping internal time. (Wait 0.1 seconds before sending the next packet.) ping –l 5600 –s 100 -i 0.1 192.168.15.200 pretty much ping of death, increases variable time, and increases packet size. ping 127.0.0.1 Pings local host. Date Display or change the date & time Location: /bin/date Syntax: date [-a] [-u] [-s datestr] date List the date and time of the server. for example Thu Feb9 16:47:32 MST 2011 date –s “11/20/2003 12:48:00” Set the date and time shown date ‘+DATE:%m/%d/%y%nTI ME:%H:%M:%S’ Would list the time and date in the below format. DATE: 02/08/01 TIME:16:44:55 Mkdir Create new folder(s) Location: /bin/mkdirwhich Syntax: mkdir [-m,-p,-v,-z,or directory name] directory mkdir mydir The above command creates a new directory called mydir. mkdir –m a=rwx mydir This example would use the –m option to not only create the mydir directory but also set the permissions to all users having read, write, and execute permissions mkdir –v bigdir Will display a message for each created directory Uname Print system information Location: /bin/uname Syntax: uname [-a] [-i] [-m] [-n] [p] [-r] [-s] [-v] [-x] [-S systemname] uname –arv Will list the basic system information, OS release, and OS version. uname –p Will display the Linux platform. uname –a Will print out all information. uname –v Will print out the kernel version. ~ tilde the tilde represents the home directory of the current user. ~foo Refers to the home directory of the user foo. > Redirector Redirects a file to a different output. date > RightNow.txt .> is used to replace the of any existing file having the name “RightNow.txt”. content the created aliases. Ssh Secure Shell client (remote login program) Location: /usr/bin/ssh Syntax: ssh [1246AaCfgkNnqsTtVvXxY] [-b bind_address] [-c cipher_spec] [D port] [-e escape_char] [-F configfile] [-i identity_file] [-L port:host:hostport] [-l login_name] [-m mac_spec] [-o option] [-p port] [-R p_rt:host:hostport] [user@]hostname [command] ssh –V Identifies SSH client version. ssh –l jsmith remotehost.example.co m Login to remote host. (ssh-keygen –F publickey.pub) to get public key fingerprints. scp jsmith@remotehost.e xample.com:/home/js mith/localhostfile.txt Copies the file from the remote host to the local host. Rsync Remote file copy (Synchronize file trees) Location: /usr/bin/rsync Syntax: rsync options source destination rsync –zvr /var/opt/installation/i nventory/ /root/temp -z is to enable compression -v verbose -r indicates recursive Syncs two directories in a local computer. rsync –azv /var/opt/installation/i nventory/ /root/temp/ Archives the file too. rsync –v /var/lib/rpm/Pubkeys /root/temp/Pubkeys Copies one file. ? Question mark Expands to the status of the most recently executed foreground pipeline. man -? Displays the man help list Page |6 . period Run a command script in the current shell (current directory) ./filename refers to a filename in the current directory. >> append to overwrite an existing file use “>>” to append to any existing file. date >> RightNow.txt Will attach the information about the date to the file RightNow.txt. .. Parent directory Runs a command script in the current shell. ../filename Means you are referring to a filename in parent directory. < Backwards redirector Redirects output to a different input. Sort < txtfile is the same as cat textfile | sort | pipeline A pipeline is used to make the output of one command serve as the input to another command. echo ”cherry apple peach” |tr “ “ “\n” pipes the output of echo into translation command which spaces with linefeeds, represented by “\n” * Asterisk Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable. ls * will display all directories and files. Page |7 References (2011) Computer Hope. Linux Command Help. http://www.computerhope.com/unix/usu.htm (2009) The Geek Stuff. Linux Commands. http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-command-examples/