UP | HOME

Unix/Linux Commands, Syntax, And Notes

1. UNIX / Linux Metacharacters And Syntax

  • * : match any string of characters
  • […] : match any string inside the brackets
  • ? : match any single character
  • newline : most common command terminator
  • ; : command terminator to separate input into two commands; commands are run in sequence
  • & : start the command and keep it running in the background, then take further commands immediately; also a command terminator
  • | : redirect output from the left side into the input of the right side; programs on both sides of the pipe run simultaneously, allowing for interactive functions
  • && : run first command; if successful then run second command
  • || : run first command; if unsuccessful then run second command
  • >file-name : store output in the following file, not the terminal
    • echo hello >file-name is equivalent to >file-name echo hello
  • >>file-name : store the output at the end of the file
  • <file-name: get the input from the following file
  • n <& m : merges input from stream n with stream m
  • n >& m : merges output from stream n with stream m
  • !### : execute command number from shell history
  • !command-prefix : search for and execute the last command starting with the prefix from .bash_history
  • !! : repeat the last command
  • !((partial)-command-name) : run the last occurrence of that command
  • $0…$9 : replaced by arguments to shell file (indicate arguments to be placed in a command); $* : shorthand for all the arguments; these are known as positional parameters
  • $0 stores the name of the script
  • $$ gives the process-id of the shell script
  • $? gives the return value of the last command
  • $! gives the process-id of the last command started in the background with &
  • # : comment out rest of a line
  • ’ ’ : prevent the shell from interpretted characters as metacharacters; cause shell to interpret input as a single word (does not interpret delimiters)
  • “ ” : prevent the shell from interpretted characters as metacharacters, except that the shell scans the inside of the quotes to look for #, ’…’, and \
  • `path-to-command-name` OR $(command-name): enclose the invocation of a command into the shell
  • \ : prevent the shell from interpretted characters as metacharacters
  • ( ) : group concatenate commands into a single stream; run commands in a sub-shell
  • { } : run commands in current shell
  • Arrow keys (↑ and ↓) navigate to previous commands in .bash_history
  • . : present working directory; ./program-name will run the program in the directory
  • .. : parent directory of pwd
  • ~ : home directory
  • ~<username> : another’s user’s home directory
  • / : root directory
  • – : used to precede words that are used as a command’s option. Without –, the string of characters forming the word could be perceived as a long list of individual-character-options.

1.1. UNIX Control Characters

  • ctrl + c = stop command
  • ctrl + u = kill line
  • ctrl + d = there is no more input
  • ctrl + z = suspend the program running on the command line
  • ctrl + s = pause output
  • ctrl + q = resume
  • ctrl + h = backspace

2. UNIX Commands To Remember

  • find directory-name -name “search-name” -print : recursively find file-name in directory-name; find is slower than locate since it traverses directory tree instead of a database
  • find . -name “pattern-to-search” : finds files matching pattern
  • find . -name “~\$*.docx” -delete : deletes all useless files whose names match the pattern created by microsoft word; delete files matching pattern
  • find ~ -mmin -30 -print : find all files modified in home directory in the last 30 minutes
  • grep -n expression file-name : global regular expression printer (search files and print line numbers and lines containing search expression); -y: case independent
  • grep -nr expression file-directory : search the directory recursively for the expression
  • grep -n “first.*last” file-name : (search files and print line numbers and lines beginning and ending with the patterns specified)
  • The syntax for –include is identical. Note that the star is escaped with a backslash to prevent it from being expanded by the shell (quoting it, such as –include=“*.{cpp,h}”, would work just as well). Otherwise, if you had any files in the current working directory that matched the pattern, the command line would expand to something like grep pattern -r –include=foo.cpp –include=bar.h rootdir, which would only search files named foo.cpp and bar.h, which is quite likely not what you wanted.
  • grep pattern …: …
  • script file-name : start new session and record all terminal input and output into filename; ctrl+d / exit to stop recording
  • whereis command-name : find binary files, source files, and man pages for a command
  • which command-name : show where command is located
  • cd - : toggle between two directories
  • w : show what programs users are running
  • sort : sort lines within a file (alphabetically by default)
  • kill -signal PID : send specified signal to PID
  • printenv : display environment variables
  • alias alternative-name-to-use=’command-name -options’ : create alias for command
  • ln path-to-file new-path-to-link-of-the-file : create hard link to file; hard links link to an inode, but symbolic links don’t
  • ln -s file-path-name path-link-to-file : create symbolic link to hard link (file-name)
  • javac buggy-program-name.java > error-log-for-file-name 2>&1 : send both output and the error messages into a file
  • command-name 2>file-to-store-errors : send errors to a file
  • apropos : finds online manual pages for a specified keyword
  • split file-name : a file into smaller files
  • wget –recursive –no-clobber –page-requisites –html-extension –convert-links –no-parent www.website-to-download.domain
  • curl wttr.in : Display a local weather report in the terminal.
  • objdump -d program-name : this shows the memory addresses and assembly instructions needed to run everything in the program
  • scp sourcepath/filename destinationpath:sourcepath/optionalNewFilename : secure copy program for copying files to/from remote machines; use -r to copy directories (recursively)
  • locate filename : find filenames inside a database of all file-names, which is updated by the system once a day; the database must be generated first
  • wc : word count; -c: number of bytes; -m: number of characters; -w: number of words; -l: numbers of lines
  • javac buggy-program-name.java > error-log-for-file-name 2>&1 : send both output and the error messages into a file
  • command-name 2>file-to-store-errors : send errors to a file
    • <command-with-misaligned-output> | column -t
      • The -s argument marks the separator between columns on the input. Here it’s the forward slash, because no filename, group ID, user ID, or file mode will ever have a forward slash in it.
      • The -o argument marks the separator between columns on the output. Here it’s │ (a vertical bar from the box drawing characters, surrounded by spaces).
      • The -t argument makes it display the output as a table. By default, the output of column without -t is each full line packed into columns, which doesn’t seem as useful.
  • startx : start GUI if computer only has CLI running.

3. Command Description Syntax

Built-in usage help and man pages commonly employ a small syntax to describe the valid command form:

  • Angle Brackets for required parameters: ping <hostname>
  • Square Brackets for optional parameters: mkdir [-p] <dirname>
  • Ellipses for repeated items: cp <source1> [source2…] <dest>
  • Vertical Bars for choice of items: netstat {-t|-u}

Notice that these characters have different meanings than when used directly in the shell. Angle brackets may be omitted when confusing the parameter name with a literal string is not likely.

4. Fundamental Unix Commands To Remember

  • ls -lhStuciaFG file-path
    • -l : long information
    • -h : human-readable file sizes
    • -S : sort by file size
    • -t : sort by time
    • -u : print the last time the file was read or executed
    • -c : print the last time the inode was changed
    • -i : list the system’s internal name for a file in decimal
    • -a : list all
    • -F : label files with symbols
    • -G : use color coded output (Graphic)
  • ls -R file-path : list all files and subdirectories’ contents
  • ls -ld directory-name : print information about the directory itself, not its contents
  • ls -l : list long information of a directory; format: drwsrwxrwx
  • basic commands: history; cd; cp; mv; date; cal; uptime; who; whoami; who am i; clear; passwd; top; vim; emacs; sh : summon sub-shell
  • chsh path-name-to-new-shell-listed-in-/etc/shells: change your default shell
  • rm file-name : remove the specified (filename / link / directory entry); when the last link to a file disappears, the system’s remove the inode and the file itself
  • rm -rf : remove a directory and all its contents/subdirectories without asking
  • man command; /[regular expression] : search for information inside man pages
  • file file-name : view the file’s type (makes educated guess about the file type by reading first few hundred of bytes from file)
  • touch file-name : create an empty file with a name
  • wc : word count; -c: number of bytes; -m: number of characters; -w: number of words; -l: numbers of lines
  • w : show what programs users are running
  • ps -vf : show processes that are currently running, verbosely (with extra information); ps -L, ps -O keyword, ps -O %cpu, ps -hO %mem, ps -f: extra process information
  • ps –fe | grep $USER : list only your own processes
  • ps -ef
  • sleep ## : suspend execution for numbers of seconds listed
  • time : reports the elapsed time (execution, process, and system times) for a command
  • more file-name : display the file, but one screenful at a time
  • less file-name : display the file, but enable page up and down navigation
  • head file-name : display the first few lines of a file
  • tail -# : print last lines in a file
  • tail -f : displays the newest 10 lines of a program (useful for monitoring files being written by running programs)
  • man -k keyword : search man pages that contain keyword; used for finding programs to do what you want
  • man -f command : one line summary of command
  • uname -a : print operating system information
  • hostname : print the name of the machine that is logged on
  • host hostname : print the internet address of a machine
  • ssh : secure encrypted client shell to login to remote machines
  • ssh-keygen -t : generates a public and private key for secure shell logging into a system without a password
  • scp sourcepath/filename destinationpath:sourcepath/optionalNewFilename : secure copy program for copying files to/from remote machines; use -r to copy directories (recursively)
  • script file-name : start new session and record all terminal input and output into filename; ctrl+d / exit to stop recording
  • grep -n expression file-name: global regular expression printer (search files and print line numbers and lines containing search expression); -y: case independent
  • grep -n “first.*last” file-name: (search files and print line numbers and lines beginning and ending with the patterns specified)
  • grep -nr expression file-directory: search the directory recursively for the expression
  • locate filename : find filenames inside a database of all file-names, which is updated by the system once a day; the database must be generated first
  • last -# (user-name) : print last logins of users and ttys
    • sort : sort lines within a file (alphabetically by default)
  • mail : send mail to users or email addresses (must be configured); mesg y / mesg n : display messages from other users
    • ## : type number corresponding to message that you want to read
    • d ## : delete the message associated with the number
    • s : save a message into a file
    • q : exit out of mail and save all messages (without deleting) into the file mbox in your home directory
    • mail user-name : write message to user
    • ctrl-d : send message
    • R : Reply : reply to a message
  • cmp : compare two files (check for similarity)
  • diff : report all lines that are changed, added, or deleted from one file to the next (specified in arguments)
  • diff3 : report all lines that are changed, added, or deleted between three files (specified in arguments)
  • su : switch user (default is super user)
  • adduser, addgroup <username>: add a user or group to the system
  • useradd -c “FullName” username
  • newgrp : changes the group permissions to another group
  • passwd : changes the password for the user on the terminal
  • kill -signal PID : send specified signal to PID
  • kill PID : send default signal to PID
  • kill 0 process-id : stop all processes except the login shell
  • kill -9 process-id : kill commands not responding to the kill command by using the SIGKILL signal
  • nohup command-name & : continue to run the command if you log out (“no hangup”); output will be saved in a file called nohup.out
  • nice command-name & : run the process with a lower than normal priority
  • whereis command-name : find executable files for a command
  • which command-name : show where command is located
  • printenv : display environment variables
  • tty : print which terminal is being used
  • pr file-names : print files
  • at [time] command(s) [ctrl+d] : run the command(s) at the specified time (24-hour 2130 or 12-hour style 930pm)
  • echo [text-to-be-printed] : print text that is printed; -n: print the text without printing a following newline
  • ps augwx : print all processes on the system
  • ps ax : print list of the current set of processes
  • dd : convert and copy a file, usually raw, unformatted data from tapes.
  • chfn : change your personal information like phone number, office location, your real name etc.
  • export variable-name=whatever-you-want-it-to-be : define/redefine a variable; makes defined variables available to all sub-shells
  • alias alternative-name-to-use=’command-name -options’ : create alias for command
  • basename file-path-name : print the name of the file without printing its parent directories
  • basename file-name.extension extension-to-be-removed : remove the extension of a file
  • test $variable-name = value : test and return a boolean value; often used in conditional statements
  • test -f : test is a file is a regular file or a directory
  • test $variable-name -ge number-to-be-compared : compare two numbers and return a boolean value; often used in conditional statements
  • ls | wc -l : list the number of items in a folder
  • cal -3 : print the calendar of last month, this month, and next month
  • curl : transfer a URL
  • history | tail -20 : print the last 20 commands
  • timeout ## : run the process, and kill it after ## seconds if it hasn’t ended already
  • <command-with-misaligned-output> | column -t
    • The -s argument marks the separator between columns on the input. Here it’s the forward slash, because no filename, group ID, user ID, or file mode will ever have a forward slash in it.
    • The -o argument marks the separator between columns on the output. Here it’s │ (a vertical bar from the box drawing characters, surrounded by spaces).
    • The -t argument makes it display the output as a table. By default, the output of column without -t is each full line packed into columns, which doesn’t seem as useful.

5. Root Directories In The File System

/boot Linux kernel and boot loader
/dev Special device files
/etc System configuration files
/home Home directory files
/lib Library files for programs
/mnt Mounts points for external storage devices
/root Home directory of root user
/sbin System-administration commands
/tmp Temporary directory
/usr Many important programs
/var Various system files, such as logs

These are the common top-level directories associated with the root directory:

/bin binary or executable programs.
/boot It contains all the boot-related information files and folders such as conf, grub, etc.
/cdrom Historical Mount Point for CD-ROMs
/dev It is the location of the device files such as dev/sda1, dev/sda2, etc.
/etc system configuration files.
/home home directory. It is the default current directory.
/lib It contains kernel modules and a shared library.
/lost+found It is used to find recovered bits of corrupted files.
/media It contains subdirectories where removal media devices inserted.
/mnt It contains temporary mount directories for mounting the file system.
/opt optional or third-party software.
/proc It is a virtual and pseudo-file system to contains info about the running processes with a specific process ID or PID.
/root Home directory of root user
/run It stores volatile runtime data.
/sbin binary executable programs for an administrator.
/srv It contains server-specific and server-related files.
/sys It is a virtual filesystem for modern Linux distributions to store and allows modification of the devices connected to the system.
/tmp temporary space, typically cleared on reboot.
/usr User related programs.
/var Various system files, such as logs.

5.1. The First Character Of ls -l

In the ’ls -l’ output, the first character can be any of these:

  • d : directory
  • - : regular file
  • l : symbolic link
  • s : Unix domain socket
  • p : named pipe
  • c : character device file
  • b : block device file

6. Man Manual Sections

The standard sections of the manual include:

  • 1 User Commands
  • 2 System Calls
  • 3 C Library Functions
  • 4 Devices and Special Files
  • 5 File Formats and Conventions
  • 6 Games et. al.
  • 7 Miscellaneous
  • 8 System Administration tools and Daemons

Distributions customize the manual section to their specifics, which often include additional sections.

7. File Systems And Security Commands

  • cd - : toggle between two directories
  • pushd other-directory-to-switch-to : push the current directory onto the directory stack and switch to the directory stated
  • popd : pop the top directory on the directory stack and cd to it
  • od file-name : octal dump (visible representation of all bytes in file); 7-digit numbers indicate next position
    • -c: interpret bytes as characters, -b: show bytes too; -x: hex; -d: decimal
  • pwd : print working directory
  • find directory-name -name “search-name” -print : recursively find file-name in directory-name; find is slower than locate since it traverses directory tree instead of a database
  • find . -name “pattern-to-search” : finds files matching pattern
  • find . -name “~\$*.docx” -delete : deletes all useless files whose names match the pattern created by microsoft word; delete files matching pattern
  • find ~ -mmin -30 -print : find all files modified in home directory in the last 30 minutes
  • which program-name : locate program file in user’s path
  • du -h : disk usage, tell how much disk space is consumed by the files in a directory, including all its subdirectories; -a: all files, including subdirectories
  • du -sh directory-name : print total sum usage of a directory
  • du -a | grep file-name : search for specific files in a directory
  • ln file-path-name path-link-to-file : create hard link to file; hard links link to an inode, but symbolic links don’t
  • ln -s file-path-name path-link-to-file : create symbolic link to hard link (file-name)
  • chmod permissions file-names : change permissions on files (change mode); permissions can be specified either as octal numbers or using symbolic descriptions
  • chmod ### file-names : each single octal digit specifies the rwx for the file owner, group, and other users respectively: 4 for read, 2 for write, and 1 for execute permission
  • chmod u+/-=rwx g+-=rwx o+-/=rwx file-names :
    • + turns a permission on,
    • - turns a permission off for the file owner, group, or other users.
    • changes for all users if unspecified
  • chmod -R ### / +/- rwx directory-name : change the permissions on directory and subdirectories recursively
  • chown login-id file-name : change ownership; user must have the privelages of the target user. In most cases, only root can transfer file ownership
  • chown login-id group-id file-name : change ownership of file owner and group
  • crypt : encrypt files; note that the super-user could change the crypt the algorithm or command
  • gzip file-names : compresses files in order to save space; the extension .gz is added to files that it compresses
  • tar -cvf tarball-name.tar directory-to-be-bundled : Tape ARchive; recursively bundle directory into single file, called a tarball; -c: create; -f: choose name to follow
  • tar -tvf : -t: list table of contents for tarball without extracting (the tar program does preserve metadata while archiving)
  • tar -xvf tarball-name.tar : -x: extracts files from tarball
  • tar -czvf tarball-name.tar.gz directory-to-be-bundled : -z: create a tarball that is also compressed by gzip; uses the extension .tar.gz or .tgz by convention
  • tar -xzvf tarball-name.tar.gz : -xz: extracts files from a compressed tarball
  • tar -cjvf tarball-name.tar.bz2 directory-to-be-bundled : -j: create a tarball that is compressed by bzip2
  • tar -xjvf tarball-name.tar.bz2 directory-to-be-bundled : -j: unpack a tarball that was compressed by bzip2
  • zip -r file-name.zip directory-name : compression and archive tool available on all operating systems; generally not preferred on Linux since it doesn’t preserve metadata
  • unzip directory-name.zip : uncompress zip archive
  • quota -v : show current disk space usage and limit for a user (if there is one)
  • df -h : examine the available free space on all mounted disk file systems; -k: display all filesystems including remote ones
  • lsblk : list all the storage devices (block devices) connected to the system
  • sudo fdisk partition-name : commandline utility to create, remove, manage, allocate partitions on block device
  • sudo mkfs -t file-system-type partition-name : make disk file system on block storage device
  • mount block-storage-device-to-be-mounted filesystem-location-to-be-mounted-on : mount block storage device to the filesystem
  • umount block-storage-device : disconnect block device from filesystem
  • pmap PID : Look the memory mapped zones (including shared libraries) of process PID
  • dhclient -v :

8. Filters, Pipes, And Redirection

  • tee [file-name] : copy standard input directly into standard output (unbuffered) and optionally another file.
  • uniq – report or filter out repeated lines in a file; -c: print line number and a space before every outputted line
  • tr : transliterates the characters in its input; a-z A-Z: convert lowercase letters to uppercase; A-Z a-z: convert uppercase letters to lowercase letters; A-Za-z: all letters
  • comm -options file-name-1 file-name-2 : print three columns of output: lines that only occur in file-name-1, lines that only in file-name-2, lines that occurs in both files; -1: suppress column 1; -2: suppress column2; -3 suppress column3; -i: case insensitive comparison
  • sed ’list-of-commands’ file-names : (Stream EDitor) read lines one at a time from the input files, apply commands from the list (placed within single quotes), in order, to each line and write the edited output to the standard output; -n ’/pattern/p’: only explicitly print patterns with the p command
    • sed ’s/$/\n/’ : prints a newline to the end of each line, thus double spacing a file
    • sed -n ’20,30p’ : print lines 20 through 30
    • sed ’1,10d’ : delete lines 1 through 10
    • sed ’1,/^$/d’ : delete up to and including the first blank line
    • sed ’$d’ : delete last line
  • awk ’program-name’ file-names : read lines from an input file and divide them into strings of non-blank characters separated by blanks or tabs. Fields ($1, $2, $NF, $0) apply to the lines like columns; -F@: change the delimiter between fields in any single character (@), like a colon, |, or any other character
  • javac buggy-program-name.java > error-log-for-file-name 2>&1 : send both output and the error messages into a file
  • command-name 2>file-to-store-errors : send errors to a file
  • jobs : print all background jobs started from the current shell
  • fg %# : bring command into the foreground, where # is the job number associated with the command, as listed by the jobs command; often used on processes stopped by ctrl+z
    • Often used to resume suspended Emacs sessions
  • bg : put a command in the background

9. Shell Scripting

  • set : display the values of all defined variables
  • say : speak the following English phrase (MacOS)
  • open path-to-file : open file with default application
  • open -a path-to-application path-to-file : open file with the application specified
  • source file-name : parse file-name
  • Shell programming comes in two flavors: shell scripts and shell functions.
  • Shell scripts, once defined, can be executed just like any other executable as long as they are set to executable. To execute any file, just type the pathname to the file.
  • Shell scripts are executed in subshells.
  • Shell functions are similar to shell scripts but are defined in the environment. This simply means that they load much faster than shell scripts and can change the current environment.
  • Shell functions are generally defined in a file and sourced into the environment.
  • Almost any command line entry can go into a shell script file.
  • The first line, called the shebang, contains the file path to the command interpreter. Shell scripts can be used with any interpreter, not just shell languages.
  • For debugging scripts, bash -x scriptname.sh will display the commands as it runs them.
  • # is used to write comments in the code and such. The variable $# gives the number of command line arguments.
  • The output of any program can be placed in a commandline (or as the right hand side of an assignment) by enclosing invocation in back quotes: ‘cmd‘ or using the preferred syntax $(cmd).
  • Shell variables are created when assigned. The assignment statement has strict syntax. There must be no spaces around the = sign and assigned value must be a single word, which means it must be quoted if necessary.
  • Variables defined in the shell can be made available to shell scripts and programs by exporting them to be environment variables.
  • echo $i\n; printf “%02d\n” $i;
  • for loops:

    for variable in list-of-words
    do
        commands
    done # denotes the end of a for loop
    for variable in list-of-words; do commands; done
    for ((i=0; i<10; i++))
        > do
        >   echo $i
        > done
    
  • while loops:

    while command
    do
        commands
    done
    while command; do commands; done
    
  • until loops:

    until command
    do
        commands
    done
    until command; do commands; done
    
  • if statements:

    if command # Use [ ] brackets to treat the stuff in between as a test without using the test command itself
    then
        commands
    else # elif can be used short for else if command, then ...
        commands
    fi # denotes the end of an if statement
    
  • case statements:

    case word in pattern
                 pattern) commands;;
                          pattern) commands;;
                          ...
                          esac # case spelled backwards
    

10. Fedora Yum RPM Commands

  • sudo yum update
  • sudo yum group list ; list groups of additional software
  • sudo yum search package-name
  • sudo yum provides command-name ; search for package that provides command
  • sudo yum info package-name
  • sudo yum install package-name
  • sudo yum remove package-name
  • sudo rpm –import repository
  • nproc : find number of processors available on the system
  • lscpu : find details about the processors
  • free - h : find the amount of memory on the system in human reable units
  • ispell file-name : interactive spell checker on a file
  • spell file-name : print out all the mispelled words in a file of words
    • both spell commands use a dictionary located in /usr/share/dict/words
  • watch -n ## program-name-to-be-executed-every-##-seconds : execute a program or command every # seconds
  • pick list-of-arguments : presents arguments one at a time and awaits for a response to use them or not (great for piping)

11. Special Linux Commands To Be Installed

  • finger : user information lookup program
    • ’finger’ reports the same information as ’who’ does, but it also looks up the user’s real name (if it’s in the user password file), tells how long the terminal has been idle. It also cuts the ’tty’ from the terminal names.
    • If the system administrator has entered the information, ’finger’ also shows an office phone number, room number, and other information about where the user works.
    • Some systems, mainly main network machines at universities have set up ’finger’ to return user-directory information.
  • finger specific-user’s-name : only list the information about that user for all the termainals they are logged into
    • .project and .plan list the current project and witty remarks of the user.
  • finger specific-user’s-name : only list the information about that user for all the termainals they are logged into
    • finger @system-name : list information about nearby system
    • finger user-name@system-name : list information about individual on nearby system
      • Note: In principle, you can finger any machine on the internet, but in many cases you get “connection refused” or even no response since they don’t have to answer
  • tree directory-name : graphical tree of file system
  • htop : improved top
  • bzip2 / xz : improved gzip
  • ripgrep : improved grep
  • mutt : mail program with a better interface
  • apt-fast : faster than apt-get since uses multiple connections simultaneously
  • g++ file-name : compile program using GNU C++ compiler
  • gmake file-name :
  • gmake 2>&1 | less : launch compilation with a pager; useful when there are a lot of error messages
  • gdb file-name : debug file with GNU debugger
  • gdb file-name core_file : examine a core dump file generated by program file-name
  • neofetch : display aesthetic ASCII rendering of system specs. Better than archey.
  • .zsh : A utility that keeps track of which directories you visit the most, and creates an index to help you switch to those directories faster in the future.

11.1. List Of Improved UNIX Utilities Vs Common Standards

  • Doom-Emacs Versus Emacs
  • NeoVim Versus Vim
  • Zshell Versus Bash
  • htop Versus top
  • ripgrep Versus grep
  • apt-fast Versus apt-get
  • bzip2 / xz Versus gzip
  • qalc - Calculator

12. Summary Of Common Linux Commands Not Listed Above

  • apropos : finds online manual pages for a specified keyword
  • batch : executive commands when load permits
  • calendar : invoke a reminder service
  • cancel : cancel a request to printer
  • chgrp : change group ownership of files
  • compress : compresses files
  • copy : copy groups of files in directories
  • cpio : archive and extract files
  • cron : clock daemon (executes batch and at commands)
  • crontab : schedule commands at regular intervals
  • csh : invoke the C shell
  • csplit : split a file into several files
  • cu : call up another Unix system
  • cut : cut selected fields from each line of a file
  • dircmp : compare two directories
  • eject : eject the media from a drive
  • expand : converts all tabs into spaces
  • expr : evaluate boolean and arithmetic expressions
  • false : return nonzero (false) exit status
  • fgrep : “fast” version of grep
  • fold : wraps each line of text to fit a specified width
  • format : format disks and cartridge tapes
  • fsck : checks and repairs a file system
  • ftp : transfer files to and from remote systems
  • groff : format files for printing
  • groups : prints the list of groups that includes a specified user
  • id : displays the user and group ID for a specified user name
  • info : displays online help information about a specified command
  • insmod : load a kernel module
  • join : display the join (lines with common field) of two files
  • ksh : invoke the Korn shell
  • ldd : displays the shared librasies needed to run a program
  • line : read a line (shell script usage)
  • logname : get login name
  • lp, lpr : send request to printer
  • lpc : administer printer queues
  • lprm : remove print jobs from the queue
  • lpq : report printer status
  • lsmod : list loaded kernel modules
  • mesg : grant or deny permission to receive write messages from other users
  • mknod : build a special file
  • mkswap : creates a swap space for Linux in a file or a disk partition
  • mtools : read and write MS-DOS or Windows disks
  • nl : numbers all nonblank lines in a text file and prints the lines to standard output
  • paste : merge lines of files
  • patch : updates a text file using the differences between the original and revised copy of the file
  • pstat : report system status
  • pstree : similar to ps, but shows parent-child relationships clearly
  • reboot : stops system and restarts the computer
  • recode : translates files to different formats
  • rlogin : login to remote Unix systems insecurely
  • setenv : add value to environmental variable (C Shell)
  • sh : invoke Bourne shell
  • shutdown : gracefully shut down system (root)
  • slogin : login to remote unix systems securely
  • split file-name : a file into smaller files
  • stty : set options for a terminal
  • sum : compute checksums and number of blocks for files
  • swapoff : deactivates a swap space
  • swapon : activates a swap space
  • sync : writes a buffered (saved in memory) data to files
  • tee : create a tee in a pipe
  • true : returns zero (true) exit status
  • tset : set terminal modes
  • tty : report name of terminal
  • type : shows the type and location of a command
  • umask : set file-creation mode (permissions) mask
  • uucp : copy files between two Unix systems
  • uulog : report on UUCP status
  • uuname : list UUCP sites known to this site
  • uudecode : decode to binary after uuencode transmission
  • uuencode : encode binary file for email transmission
  • uustat : report status for or cancel UUCP jobs
  • uupick : receive public files sent via UUTO
  • uuto : send public files to another Unix system
  • uux : execute command on remote Unix system
  • unalias : deletes an abbreviation defined using alias
  • uncompress : decompresses files compressed with ’compress’
  • wall : sends a message to all users (root)
  • wait : await completion of background processes
  • whatis : similar to the ’apropos’ command, but searches for complete words only
  • which : finds files in the directories listed in the PATH environment variable
  • who : list who’s using the machine
  • who am i : print just your line of information on the terminal where you typed this command
  • whoami : print only the name of the user who typed this command
  • whois : search for user information
  • rwho : compile list of all the people using all the machines on the local network
  • write user-name : send message for another user in real-time (presumably for extremely urgent messages)
  • write user-name terminal-name : send message in real-time to specific terminal used by user (ideally the one with the least idle time, or the terminal name used to send the last ’write’ message if messaging back and forth)
  • talk user-name<@machine-name> <terminal-name> : start a two-way typing conversation with another user (usually other computers)
    • If you want to respond to someone that is trying to talk to you, you must exit to the shell (if you are in the middle of a text editor or other program) and type ’talk’ in the shell.
    • If you want to talk to a number of other people (perhaps thousands of them), you can use Internet Relay Chat (IRC).
  • zcat : displays a compressed file (after decompressing)
  • zless : displays a compressed file one page at a time (can go backward also)
  • zmore : displays a compressed file one page at a time

13. UNIX Notes

  • Any commands stored in .bash_profile in the user’s login directory will be executed when the user logs in, before printing the first prompt.
  • (UTF = Unicode Transformation Format)
  • Tty stands for teletype. The rc suffix stands for “run control”; ex: .vimrc, .bashrc
  • ed > em > en > ex > vi > vim > gvim
  • The .bash_profile file in the user’s home directory is sourced for each interactive login session, while .bashrc is sourced for all interactive sessions. There are many ways to customize it.
    • export variable-name=“” : assigns a value to variables
    • set -o vi : set the editor mode to vim
      • /string : search for previous commands in .bash_history
    • alias command-alias-name=’unix-command -option’
  • man bash shows all the shell parameters, variables, and just about all the information there is to know about how to use the shell.
  • sd stands for scsi disk. sda is the first drive, sdb the second, sdc the third, and so on. The number that follows is the partition number on the drive.
  • In Linux, all applications are stored under /usr/share/applications.
  • u = single user; g = group of users; o = other users
  • stdin = standard input, stdout = standard output, stderr = standard error; the corresponding file streams are each numbered 0, 1, and 2 respectively.
  • Variables can be defined in your .profile. These could be things such as a long directory path that you constantly refer to.
  • Shell variables are usually in all caps and user-defined variables are conventionally all lower-case to distinguish the two.
  • The value of any shell variable can be obtained by prefixing the variable with $. echo $SHELL_VARIABLE can output the current value of the variable.
    • $PS1 is the shell variable responsible for the prompt string (usually $). One can set it with syntax: PS1=’whatever you want’
    • $PATH is the shell variable that controls the search path where the shell looks for commands.
    • TERM names the kind of terminal you are using.
    • ( set -o posix ; set ) | less : list all shell variables and environment variables.
  • RETURN/ENTER is interpretted by the kernel as both a carriage return and a newline, but only stores the newline / linefeed in the input.
  • Programs retrieve the data in a file by a system call called read. Each time read is called, it returns the next part of a file.
  • Input lines are not returned to the kernel until you type newline. Once newline is entered, no changes can be made because it was already read by the system.
  • Every running program (every process) has a current directory and all filenames are implicitly assumed to start with the name of that directory, unless specified otherwise.
  • Files themselves never determine what programs do with them. All files are just data, and programs determine what they do with files.
  • Files that have the same function are only the same because a set of commonly agreed standards determined that they all follow a set of conventions and have similar formatting.
  • The purpose of a file extension is thus not to determine how a file works, but to determine what programs will open a file.
  • When users enter in their passwords the passwords go through the encryption algorithm so that the system can compare it with the password on the system, which is also encrypted.
  • It’s easy to go from the clear form to the encrypted form, but very hard to go backwards.
  • People have login directories as their attributes, processes have current directories as their attributes.
  • Even though directories sit in the file system as ordinary files, only the kernel has the ability to control the contents of the directories.
  • Default search path: System first checks current directory, then /bin, then /usr/bin for program names that match the prompt input.
  • The super-user can read and write ANY file on the system.
  • The username that one uses to login is the login-id, but the number that the system recognizes users by is actually the user-id, or uid.
  • The group-id is the group identification. The information for group names, group-id’s, and which users are in which groups are stored in /etc/group.
  • /etc/passwd only identifies the the login group.
  • A program is just a file that has execute permission.
  • One cannot simply write in a directory (though one can create and delete files in a directory), even root is forbidden from doing so. Only system calls can write to directories.
  • Permission to remove a file is independent of the file itself, even for files that are protected against writing. A directory’s write permissions determine this.
  • Files cannot be removed unless the user has write privelages for the directory where the file is located.
  • Only a file’s owner and the super-user may be able to change the permissions of a file, regardless of the permissions themselves.
  • The x field for permissions on a directory mean “search” instead of execution, which determine if a directory can be searched for a file.
    • Thus, directories can be created that allow users to access files that they know are in the directory, while preventing them from reading what files are in the directory.
  • The inodes (originally i-nodes and index-nodes) identifies the permissions and dates for the files; The three times/dates in the inode are: the time when the contents of the file were last modified (written), the time that the file was last used (read or executed), and the time that the inode itself was last changed.
  • In the context of Unix file systems, “metadata” is information about a file: who owns it, permissions, file type (special, regular, named pipe, etc) and which disk-blocks the file uses, which is all typically contained in the inodes in the on-disk structure.
  • The usage time for a file reported by ls -lu reports when the file was last used, not when it was last written to.
  • Changing permissions only affects the inode change time, as reported by ls -lc.
  • All the directory hiearchy does is provide convenient names for files. The system’s internal name for a file is its i-number: the number of the inode holding the file’s info.
  • When a directory entry is zero (see od -d), then the link has been removed, but not the contents of the file as long as there is still another link in the filesystem.
  • /dev is where devices get connected to the filesystem and unix system. Inside the kernel, references to that file are converted into hardware commands to access devices.
  • Links can be anywhere as long as they’re not between two subsystems, since they can unmounted, don’t have unique inodes between systems, and have limits on file size and inodes.
  • Hard links cannot be made to directories, but soft symbolic links can.
  • Hard links link directly the inodes. Every file has at least one hard link. Symbolic links can only link to a hard link. If the hard link that the symbolic link is linked to is deleted, then the symbolic link will be left dangling and pointing to no object.
  • When a disk space quota is exceeded, the system grants the user seven days to remove or compress files until they are below the quota, or else it will suspend login priveleges.
  • Only the user can read from or write to their terminal. The device /dev/tty# is a synonym for the login terminal.
  • In one context, file system refers to the directory hierarchy that a user interacts with when using command line tools or browsing for a file. However, file system also refers to the software layer that manages how files are stored and retrieved from physical storage devices such as hard disk drives, USB thumb drives, solid state drives, etc.
  • Linux supports a large number of file systems, each with their own pros and cons. The various disk file systems try to balance read performance, write performance, large file performance, small file performance, reliability, and recoverability. There is not a perfect solution, which is why there are so many options. The xfs disk file system is the default for CentOS while ext4 is the default for Ubuntu and Fedora Linux. Both provide a good balance for workloads typically associated with a development workstation.
  • /etc/fstab is the file system table that determines which storage devices are automatically mounted at boot.
  • Ctrl + C sends SIGNINT / TERM signal to a command. Ctrl + Z sends the STOP signal to a command.
  • The AWK Programming Language by Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger, Addison Wesley.
  • awk is based on the C Programming Language and it can implement arrays, loops, if-statements, and other full programming language statements based on C. An entire book has been written on it and it is a stand-alone programming language specialized for text-processing.
  • There are three data streams associated with every command ran under Linux: stdin, stdout, and stderr (standard input, standard output, and standard error). The corresponding file numbers for all of these are 0, 1, and 2; 2>: redirect error messages from stderr to stdout
  • File matching characters do not look at filenames beginning with a dot unless explicitly specified.
  • Single quotes protect double quotes and double quotes protect single quotes inside the shell.
  • In shell terminology, a word is defined as any single string that a shell accepts as a unit, including blanks if they are quoted.
  • ’> ’ is a secondary prompt printed by the shell when it expects the user to type more input to complete a command.
  • A backslash at the end of a line causes the input to be continued below the line. Newlines are discarded when preceded by a backslash, but retained when in quotes.
  • The value of a variable is associated with the shell that creates it, and is not automatically passed to the shell’s sub-shells unless the export command is used.
  • Every program has three default files established when it starts, numbered by three file descriptors: 0,1,2 (stdin, stdout, stderr); 1>&2 can add stdout to stderr.
  • The grep family of programs supports character classes. Since egrep is faster and can search for more general expressions that the original grep, they got combined into a single pattern matching program is some Unix distributions.
  • In Vim, :%s/ OR / + up-down-arrows can enable one to search using past strings
  • How Most Linux Package Managers Work: 1. Download .rpm/.pkg/… file. The package manager will: 1. unpack the file (decompress & extract the files), 2. put the resulting little files in their correct places, and 3. update a database of installed software on the computer.
    • If you later want to install an upgrade, the package manager remembers an older version is already installed and saves any existing configuration files while upgrading the necessary files.
    • You can only install software using a package manager if you are the system administrator.
  • Shar (shell archive) messages are a way to send messages to other users. First you save the message in a separate file, delete all the lines at the beginning of the file until the first line that starts with #, and feed the saved file into a shell with the syntax: sh shar-file-to-be-read
    • The command will run the script in the file and create the program files or whatever else is in the shar file. Then you delete the saved shar file since it’s not needed anymore, and move the created files to the appropriate place, probably to the your bin directory.
  • To install programs from uuencode files (typically binary programs), save the uuencode message into a file, and feed the uuedecode program with the line: uudecode uu-file-to-read
    • The command will run the script in the file and create the program files or whatever else is in the uuencode file. Then you delete the saved uuencode file since it’s not needed anymore, and move the created files to the appropriate place, probably to the your bin directory.
  • UNIX was designed as a multi-user system from the very beginning, in part because it was very expensive to buy a computer back then for only one person.
  • Computers use all kinds of protocols to communicate.
    • On a network, clients connect to servers by using protocols such as TCP/IP (Transmission Control Protocol / Internet Protocol) and IPX (Internetwork Packet eXchange).
    • Computers connected by the Internet exchange files by using protocols such as FTP (File Transfer Protocol) and HTTP (HyperText Transfer Protocol).
    • SMB is a protocol included in all versions of Windows that enables communication between UNIX and Windows computers.
      • Samba is a suite of programs who can turn any version of UNIX into an SMB server.
      • SMB is a request-response protocol, in which a client makes requests of the server, and the server responds. A client usually has to make several requests to a server before anything useful happens, including which dialect of SMB it wants to speak, and a username and password. If the server accepts, the client can petition the server with a series of requests - for example: to locate, open, and print a particular file.
  • The whereis command shows you the location for the binary, source, and man pages for a command, whereas the which command only shows you the location of the binary for the command.
  • When the internet was first starting, people used their phone lines to connect to the internet?

Last Modified: 2023 October 03, 10:12

Author: Zero Contradictions