====== Some Basic Unix Commands ====== ====== Required Reading ====== - [[unix_101|Unix 101 -- An absolute beginner's guide to Unix and Linux]] ====== Finding Commands ====== Most user-level commands can be found in the ''/bin'', ''/usr/bin'', and ''/usr/local/bin'' directories. Some programs can be found in ''/sbin'' and/or ''/usr/sbin'', but those programs are usually reserved for the administrator, and they won't work for you unless you have the password. You can also use the ''man'' command to search for commands by keyword, but search is limited. Google is probably a better choice unless you know a specific keyword you're looking for. ====== A List Of Some Popular Commands ====== ^ Command ^ Description ^ ^ arch | Outputs the hardware architecture of the current machine. $ arch x86_64 [[http://manpages.ubuntu.com/manpages/xenial/en/man1/arch.1.html|Man Page]] | ^ awk | A very powerful text processing program. Entire books have been dedicated to it's use, and I won't even begin to understand everything that it can do. But I'll give you some links.\\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/awk.1.html|Man Page]][[http://www.gnu.org/software/gawk/manual/gawk.html|GNU Manual]][[https://www.google.com/?gfe_rd=ssl&ei=sMVFV-SBEsGx-wW--Im4Cw#q=awk+examples|Examples]] | ^ basename | Given a path as a command line argument, output the last segment: $ basename /path/to/directory/file.txt file.txt Additionally, when given a suffix, it will strip off the suffix: $ basename /path/to/directory/file.txt .txt file [[http://manpages.ubuntu.com/manpages/xenial/en/man1/basename.1.html|Man Page]] | ^ bash | A standard shell program available on almost every Unix-based system. There's a good chance that when you open a terminal this is the shell program that the terminal runs. There are other shell programs, and each has it's own strengths and weaknesses, but for the purposes of these wiki pages the bash script will be what we focus on. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/bash.1.html|Man Page]][[https://www.gnu.org/software/bash/manual/|GNU Manual]] | ^ basename | Strip directory (and optionally suffix) from path names. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/basename.1.html|Man Page]] | ^ bc | An arbitrary-precision command line calculator. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/bc.1.html|Man Page]][[https://www.gnu.org/software/bc/manual/html_mono/bc.html|GNU Manual]][[http://www.basicallytech.com/blog/archive/23/command-line-calculations-using-bc/|Examples]] | ^ cat | Concatenate one or more files. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/cat.1.html|Man Page]] | ^ cd | Change directory. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/cd.1posix.html|Man Page]] | ^ chmod | Change file or directory permissions. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/chmod.1.html|Man Page]] [[http://www.thegeekstuff.com/2010/06/chmod-command-examples/|Examples]] | ^ chown | Change file or directory ownership. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/chown.1.html|Man Page]] | ^ clear | Clear the terminal screen. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/clear.1.html|Man Page]] | ^ cp | Copy file(s). \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/cp.1.html|Man Page]] [[http://www.thegeekstuff.com/2013/03/cp-command-examples/|Examples]] | ^ cut | Read input line at a time, removing a segment of each line before output. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/cut.1.html|Man Page]] [[http://www.thegeekstuff.com/2013/06/cut-command-examples/|Examples]] | ^ date | Return a time and date in configurable formats. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/date.1.html|Man Page]] [[http://www.thegeekstuff.com/2013/05/date-command-examples/|Examples]] | ^ df | Return the space used on a filesystem. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/df.1.html|Man Page]] [[http://www.thegeekstuff.com/2012/05/df-examples/|Examples]] | ^ dirname | Given a path as a command line argument, output everything except the last segment (the inverse of ''basename''). \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/dirname.1.html|Man Page]] | ^ echo | Output a string. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/echo.1.html|Man Page]] | ^ exec | Replace the currently running shell or script with a new command. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/exec.1posix.html|Man Page]] | ^ exit | Return an exit code to the parent shell. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/exit.1posix.html|Man Page]] | ^ export | Add a variable to the environment. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/export.1posix.html|Man Page]] | ^ file | Get information about the type of data inside a file. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/file.1.html|Man Page]] | ^ find | Locate files and/or directories according to user-supplied search criteria. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/find.1.html|Man Page]] [[http://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/|Examples]] | ^ for | A loop command: for ; do ; done [[http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html|Example]] | ^ free | Outputs information about how much memory exists and is being used. [[http://manpages.ubuntu.com/manpages/xenial/en/man1/free.1.html|Man Page]] | ^ grep | Reads input line at a time searching for a regular expression. If found, an action is taken. (Or if not found, an action is taken, depending on command line options used.) \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/grep.1.html|Man Page]] [[http://www.thegeekstuff.com/2009/03/15-practical-unix-grep-command-examples/|Examples]] | ^ gzip | Compress a file. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/gzip.1.html|Man Page]] [[https://www.rootusers.com/11-simple-gzip-examples/|Examples]] | ^ head | Reads input line at a time, outputting the first '''' lines. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/head.1.html|Man Page]] [[http://www.linfo.org/head.html|Examples]] | ^ if | A conditional command: if ; then ; fi Or a more complex example: if ; then elif ; then ; elif ; then ; ... ; fi [[http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html|Examples]] | ^ last | Ouptuts a list of users who last logged into this machine. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/last.1.html|Man Page]] | ^ less | Reads input and prints it to the screen, one page at a time. It pauses the output and gives the user a chance to read what they want. It will resume when the user pressed the space bar or the return key. This command is a newer version of the ''more'' command, which does the same thing except without some nice features like the ability to go backward or to search through the file. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/less.1.html|Man Page]] [[http://www.thegeekstuff.com/2010/02/unix-less-command-10-tips-for-effective-navigation/|Examples]] | ^ ln | Creates a symbolic (think Windows' shortcut) or hard link (file physically exists in two places on the filesystem at once). \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/ln.1.html|Man Page]] [[http://www.thegeekstuff.com/2010/10/linux-ln-command-examples/|Examples]] | ^ ls | Outputs a directory listing. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/ls.1.html|Man Page]] [[http://www.thegeekstuff.com/2009/07/linux-ls-command-examples/|Examples]] | ^ make | Searched for a file named "Makefile" or "makefile" and, if found, executes the commands within. Execution stops if an error occurs. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/make.1.html|Man Page]] [[https://www.gnu.org/software/make/manual/|GNU Manual]] | ^ mc | A text-based file manager. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/mc.1.html|Man Page]] | ^ mkdir | Create a directory. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/mkdir.1.html|Man Page]] [[http://www.linfo.org/mkdir.html|Examples]] | ^ mv | Move or rename a file or directory. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/mv.1.html|Man Page]] [[http://www.thegeekstuff.com/2010/12/mv-command-examples/|Examples]] | ^ paste | Merge lines from multiple files. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/paste.1.html|Man Page]] [[http://www.theunixschool.com/2012/07/10-examples-of-paste-command-usage-in.html|Examples]] | ^ ping | Tests to see if a remote host is reachable over the network. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/ping.1.html|Man Page]] [[http://www.thegeekstuff.com/2009/11/ping-tutorial-13-effective-ping-command-examples/|Examples]] | ^ pwd | Ouptuts the current working directory. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/pwd.1.html|Man Page]] | ^ read | Reads a line from input and stores it in an environment variable. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/read.1posix.html|Man Page]] [[http://wiki.bash-hackers.org/commands/builtin/read|Examples]] | ^ rm | Deletes a file. (**NOTE: There is no going back!**) \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/rm.1.html|Man Page]] [[http://www.thegeekstuff.com/2009/06/how-to-linux-delete-directory-using-rmdir-rm-command/|Examples]] | ^ rsync | A synchronization tool that can update, copy, or delete files between two locations -- both locally and over a network. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/rsync.1.html|Man Page]] [[http://www.thegeekstuff.com/2010/09/rsync-command-examples/|Examples]] | ^ screen | A fake terminal tool that can be used to run commands even after you log out. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/screen.1.html|Man Page]] [[https://www.gnu.org/software/screen/manual/screen.html|GNU Manual]] [[http://www.thegeekstuff.com/2010/07/screen-command-examples/|Examples]] | ^ script | A fake terminal tool that will store everything typed or printed to the terminal window into a file -- handy for recording your terminal session. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/script.1.html|Man Page]] | ^ sed | A search-and-replace text editing tool. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/sed.1.html|Man Page]] [[https://www.gnu.org/software/sed/manual/|GNU Manual]] [[http://sed.sourceforge.net/sed1line.txt|Examples]] | ^ set | This command will show you all of the environment variables currently set in your shell. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/set.1posix.html|Man Page]] [[http://wiki.bash-hackers.org/commands/builtin/set|Examples]] | ^ seq | This command takes two integer command line arguments and outputs every integer between them, inclusively, as it counts from the first to the second. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/seq.1.html|Man Page]] [[http://scienceblogs.com/gregladen/2009/09/19/fun-with-the-linux-seq-command/|Examples]] | ^ shift | Used for processing command line arguments in shell scripts. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/shift.1posix.html|Man Page]] [[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_07.html|Examples]] | ^ sort | Reads input one line at a time, sorts the lines, and then outputs the results. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/sort.1.html|Man Page]] [[http://www.thegeekstuff.com/2013/04/sort-files/|Examples]] | ^ ssh | A program for connecting to a remote host securely. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/ssh.1.html|Man Page]] [[http://www.thegeekstuff.com/2008/05/5-basic-linux-ssh-client-commands/|Examples]] | ^ tail | Reads input line at a time, only outputting the last '''' lines. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/tail.1.html|Man Page]] [[http://www.thegeekstuff.com/2009/08/10-awesome-examples-for-viewing-huge-log-files-in-unix/|Examples]] | ^ tar | A program used to pack multiple files or directories into a single file. Like a zip file, but without compression. (Compression is usually handled by a separate program like ''gzip'', ''bzip2'', or ''xz''.) \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/tar.1.html|Man Page]] [[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/|Examples]] | ^ test | Used to test certain conditional expressions. Often used with ''if'', ''for'', and ''while'' conditional statements. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/test.1.html|Man Page]] [[http://wiki.bash-hackers.org/commands/classictest|Examples]] | ^ time | Used to measure the amount of time that a command takes to execute. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/time.1.html|Man Page]] [[http://www.thegeekstuff.com/2012/01/time-command-examples/|Examples]] | ^ touch | Used to create empty files, or to update the timestamp on existing files. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/touch.1.html|Man Page]] [[http://www.thegeekstuff.com/2012/11/linux-touch-command/|Examples]] | ^ tr | Used to transform input. A simple example would be to capitalize text. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/tr.1.html|Man Page]] [[http://www.thegeekstuff.com/2012/12/linux-tr-command/|Examples]] | ^ true | Always returns a successful exit code. Used in conjunction with boolean logic expressions and/or inside ''if'', ''for'', and ''while'' conditional statements. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/true.1.html|Man Page]] | ^ uptime | Outputs the amount of time that this machine has been turned on. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/uptime.1.html|Man Page]] | ^ wc | Reads input line at a time and outputs user-specified metrics such as the number of lines, the number of words, the number of characters, or the number of bytes. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/wc.1.html|Man Page]] [[http://www.thegeekstuff.com/2013/02/wc-nl-examples/|Examples]] | ^ wget | A command line tool for interacting with a web server. Can be used to download HTML, or to download a file from a web page. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/wget.1.html|Man Page]] [[http://www.thegeekstuff.com/2009/09/the-ultimate-wget-download-guide-with-15-awesome-examples/|Examples]] | ^ which | Outputs the location of a program, if known. \\ \\ [[http://manpages.ubuntu.com/manpages/xenial/en/man1/which.1.html|Man Page]] | ^ while | A conditional loop command: while ; do ; done [[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_02.html|Examples]] | This list is by no means exhaustive!