Linux Flashcards
echo
The echo utility writes any specified operands, separated by single blank ( ') characters and followed by a newline (
\n’) character, to the standard output.
The following option is available:
-n
Do not print the trailing newline character. This may also be achieved by appending `\c’ to the end of the string, as is done by iBCS2 compatible systems.
Ctrl + E
Go to the end of current terminal line
Ctrl + A
Go to beginning of current terminal line
Ctrl + U
Erase current terminal line
clear (Ctrl + L)
clear clears your screen if this is possible. It looks in the environment for the terminal type and then in the terminfo database to figure out how to clear the screen.
exit (Ctrl + D)
Quits the terminal / command line
sleep
The sleep command suspends execution for a minimum of s seconds. If the sleep command receives a signal, it takes the standard action.
Example: $ sleep 60
cat
NAME
cat – concatenate and print files
SYNOPSIS
cat [-benstuv] [file …]
DESCRIPTION
The cat utility reads files sequentially, writing them to the standard output. The file operands are processed in command-line order. If file is a single dash (`-‘) or absent, cat reads from the standard input. If file is a UNIX domain socket, cat connects to it and then reads it until EOF.
> (redirect operator)
Takes the (string) output of the command left to the redirect operator (>) and redirects it into a file specified on the right side of the redirect operator.
diff
NAME
diff - compare files line by line
SYNOPSIS
diff [OPTION]… FILES
ls
NAME
ls – list directory contents
SYNOPSIS
ls [-ABCFGHLOPRSTUW@abcdefghiklmnopqrstuwx1] [file …]
DESCRIPTION
For each operand that names a file of a type other than directory, ls displays its name as well as any requested, associated information. For each operand that names a file of type directory, ls displays the names of files contained within that directory, as well as any requested, associated information.
If no operands are given, the contents of the current directory are displayed. If more than one operand is given, non-directory operands are displayed first; directory and non-directory operands are sorted separately and in lexicographical order.
touch
NAME
touch – change file access and modification times
SYNOPSIS
touch [-A [-][[hh]mm]SS] [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file …
DESCRIPTION
The touch utility sets the modification and access times of files. If any file does not exist, it is created with default permissions.
By default, touch changes both modification and access times. The -a and -m flags may be used to select the access time or the modification time individually. Selecting both is equivalent to the default. By default, the timestamps are set to the current time. The -t flag explicitly specifies a different time, and the -r flag specifies to set the times those of the specified file. The -A flag adjusts the values by a specified amount.
Quiz: How to list all files of a directory ordered by the modification time showing the ones that have been modified most recently at the bottom?
ls -rtl
mv
NAME
mv – move files
SYNOPSIS
mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source … directory
DESCRIPTION
In its first form, the mv utility renames the file named by the source operand to the destination path named by the target operand. This form is assumed when the last operand does not name an already existing directory.
In its second form, mv moves each file named by a source operand to a destination file in the existing directory named by the directory operand. The destination path for each operand is the pathname produced by the concatenation of
the last operand, a slash, and the final pathname component of the named file.
cp
NAME
cp – copy files
SYNOPSIS
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file … target_directory
DESCRIPTION
In the first synopsis form, the cp utility copies the contents of the source_file to the target_file. In the second synopsis form, the contents of each named source_file is copied to the destination target_directory. The names of the files themselves are not changed. If cp detects an attempt to copy a file to itself, the copy will fail.
rm
NAME
rm, unlink – remove directory entries
SYNOPSIS
rm [-dfiPRrvW] file …
unlink file
DESCRIPTION
The rm utility attempts to remove the non-directory type files specified on the command line. If the permissions of the file do not permit writing, and the standard input device is a terminal, the user is prompted (on the standard error output) for confirmation.
which
NAME
which – locate a program file in the user’s path
SYNOPSIS
which [-as] program …
DESCRIPTION
The which utility takes a list of command names and searches the path for each executable file that would be run had these commands actually been invoked.
curl
NAME
curl - transfer a URL
SYNOPSIS
curl [options] [URL…]
DESCRIPTION
curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction.
curl offers a busload of useful tricks like proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer resume, Metalink, and more. As you will see below, the number of features will make your head spin!
curl is powered by libcurl for all transfer-related features. See libcurl(3)
for details.
Ctrl + R ( bck-i-search)
Lets you search interactively through your previous commands, and then optionally edit the result before executing.
grep
NAME
grep, egrep, fgrep, zgrep, zegrep, zfgrep – file pattern searcher
SYNOPSIS
grep [-abcdDEFGHhIiJLlmnOopqRSsUVvwxZ] [-A num] [-B num] [-C[num]] [-e pattern] [-f file] [–binary-files=value] [–color[=when]] [–colour[=when]] [–context[=num]] [–label] [–line-buffered] [–null] [pattern] [file …]
DESCRIPTION
The grep utility searches any given input files, selecting lines that match one or more patterns. By default, a pattern matches an input line if the regular expression (RE) in the pattern matches the input line without its trailing newline. An empty expression matches every line. Each input line that matches at least one of the patterns is written to the standard output.
head
NAME
head – display first lines of a file
SYNOPSIS
head [-n count | -c bytes] [file …]
DESCRIPTION
This filter displays the first count lines or bytes of each of the specified files, or of the standard input if no files are specified. If count is omitted it defaults to 10.
If more than a single file is specified, each file is preceded by a header consisting of the string ``==> XXX
tail
NAME
tail – display the last part of a file
SYNOPSIS
tail [-F | -f | -r] [-q] [-b number | -c number | -n number] [file …]
DESCRIPTION
The tail utility displays the contents of file or, by default, its standard input, to the standard output.
The display begins at a byte, line or 512-byte block location in the input. Numbers having a leading plus (+') sign are relative to the beginning of the input, for example,
-c +2'' starts the display at the second byte of the input. Numbers having a leading minus (
-‘) sign or no explicit sign are relative to the end of the input, for example, -n 2'' displays the last two lines of the input. The default starting location is
-n 10’’, or the last 10 lines of the input.
wc
NAME
wc – word, line, character, and byte count
SYNOPSIS
wc [-clmw] [file …]
DESCRIPTION
The wc utility displays the number of lines, words, and bytes contained in each input file, or standard input (if no file is specified) to the standard output. A line is defined as a string of characters delimited by a character.
Characters beyond the final character will not be included in the line count.
A word is defined as a string of characters delimited by white space characters. White space characters are the set of characters for which the iswspace(3) function returns true. If more than one input file is specified, a line of cumulative counts for all the files is displayed on a separate line after the output for the last file.
od
NAME
od – octal, decimal, hex, ASCII dump
SYNOPSIS
od [-aBbcDdeFfHhIiLlOosvXx] [-A base] [-j skip] [-N length] [-t type] [[+]offset[.][Bb]] [file …]
DESCRIPTION
The od utility is a filter which displays the specified files, or standard input if no files are specified, in a user specified format.
sort
d
uniq
d
sed
d
ack
d
ag
d
more
d
less
d
ps
NAME
ps – process status
SYNOPSIS
ps [-AaCcEefhjlMmrSTvwXx] [-O fmt | -o fmt] [-G gid[,gid…]] [-g grp[,grp…]] [-u uid[,uid…]] [-p pid[,pid…]] [-t tty[,tty…]] [-U user[,user…]]
ps [-L]
DESCRIPTION
The ps utility displays a header line, followed by lines containing information about all of your processes that have controlling terminals.
A different set of processes can be selected for display by using any combination of the -a, -G, -g, -p, -T, -t, -U, and -u options. If more than one of these options are given, then ps will select all processes which are matched by at least one of the given options. For the processes which have been selected for display, ps will usually display one line per process. The -M option may result in multiple output lines (one line per thread) for some processes. By default all of these output lines are sorted first by controlling terminal, then by process ID. The -m, -r, and -v options will change the sort order. If more than one sorting option was given, then the selected processes will be sorted by the last sorting option which was specified. For the processes which have been selected for display, the information to display is selected based on a set of keywords (see the -L, -O, and -o options). The default output format includes, for each process, the process' ID, controlling terminal, CPU time (including both user and system time), state, and associated command.
kill
NAME
kill – terminate or signal a process
SYNOPSIS kill [-s signal_name] pid ... kill -l [exit_status] kill -signal_name pid ... kill -signal_number pid ...
DESCRIPTION
The kill utility sends a signal to the processes specified by the pid operand(s). Only the super-user may send signals to other users’ processes.
pgrep, pkill
NAME
pgrep, pkill – find or signal processes by name
SYNOPSIS
pgrep [-Lafilnoqvx] [-F pidfile] [-G gid] [-P ppid] [-U uid] [-d delim] [-g pgrp] [-t tty] [-u euid] pattern …
pkill [-signal] [-ILafilnovx] [-F pidfile] [-G gid] [-P ppid] [-U uid] [-g pgrp] [-t tty] [-u euid] pattern …
DESCRIPTION
The pgrep command searches the process table on the running system and prints the process IDs of all processes that match the criteria given on the command line.
The pkill command searches the process table on the running system and signals all processes that match the criteria given on the command line.
top
NAME
top - display and update sorted information about processes
SYNOPSIS top [-a | -d | -e | -c ] [-F | -f] [-h] [-i ] [-l ] [-ncols ] [-o ] [-O ] [-R | -r] [-S] [-s ] [-n ] [-stats ] [-pid ] [-user ] [-U ] [-u]
DESCRIPTION
The top program periodically displays a sorted list of system processes. The default sorting key is pid, but other keys can be used instead. Various output options are avail-
able.
ssh
NAME
ssh – OpenSSH SSH client (remote login program)
SYNOPSIS
ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile] [-I pkcs11]
[-i identity_file] [-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port]
[-w local_tun[:remote_tun]] [user@]hostname [command]
DESCRIPTION ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It is intended to replace rlogin and rsh, and provide secure encrypted communications between two untrusted hosts over an insecure network. X11 connections and arbitrary TCP ports can also be forwarded over the secure channel.
ssh connects and logs into the specified hostname (with optional username). The user must prove his/her identity to the remote machine using one of several methods depending on the protocol version used (see below).
If command is specified, it is executed on the remote host instead of a login shell.
file
d
ln
NAME
link, ln – make links
SYNOPSIS
ln [-Ffhinsv] source_file [target_file]
ln [-Ffhinsv] source_file … target_dir
link source_file target_file
DESCRIPTION
The ln utility creates a new directory entry (linked file) which has the same modes as the original file. It is useful for maintaining multiple copies of a file in many places at once without using up storage for the copies; instead, a link points to the original copy. There are two types of links; hard links and symbolic links. How a link points to a file is one of the differences between a hard and symbolic link.
launchd
NAME
launchd – System wide and per-user daemon/agent manager
SYNOPSIS
launchd [-d] [-D] [-s] [-S SessionType] [– command [args …]]
DESCRIPTION
launchd manages processes, both for the system as a whole and for individual users. The primary and preferred interface to launchd is via the launchctl(1) tool which (among other options) allows the user or administrator to load and unload jobs. Where possible, it is preferable for jobs to launch on demand based on criteria specified in their respective configuration files. During boot launchd is invoked by the kernel to run as the first process on the sys-tem and to further bootstrap the rest of the system.
You cannot invoke launchd directly.
ENVIRONMENTAL VARIABLES
LAUNCHD_SOCKET This variable is exported when invoking a command via the launchd command line. It informs launchctl how to find the correct launchd to talk to.
launchctl
NAME
launchctl – Interfaces with launchd
SYNOPSIS
launchctl [subcommand [arguments …]]
DESCRIPTION
launchctl interfaces with launchd to load, unload daemons/agents and generally control launchd. launchctl supports taking subcommands on the command line, interactively or even redirected from standard input. These commands can be stored in $HOME/.launchd.conf or /etc/launchd.conf to be read at the time launchd starts.
alias
Example: $alias rtest=’bundle exec rake test’