deleted-124743_linux-basic-commands
deleted-124743_linux-basic-commands
cat file1 file2 ... Print the contents of file1, * A number of any characters
file2, ... ? A single character
ls List the contents of a directory. [] Specify a range. [ab] can become: a, b. [a-c] can
ls -l Use a long listing format become: a, b, c
ls -a Do not ignore entries starting with . [!a-c] Any single character except a, b, c
cp file1 file2 Copy file1 to file2 Globbing is the operation that expands a wildcard pattern into the list
cp file1 ... fileN dir Copy a number of files to a of pathnames
directory It is applied on each of the components of a pathname separately. /
in a pathname cannot be matched.
mv file1 file2 Rename file1 to file2
If filename starts with ., . must be matched explicitly.
mv file1 ... fileN dir Move a number of files to a
Wildcard patterns are not regular expressions, they match filenames,
directory
not text.
touch file Create a file. If the file already
exists, touch does not change it Search files
rm file Remove a file grep RegEx file Search for regular expression
rm -r dir Recursively remove all files and pattern in file
subdirectories in dir grep -i Case-insensitive search
echo Print echo's arguments to the grep -v Print all lines that don't match
standard output
find dir -name file -print Find file in dir and display
pwd Print working directory
the pathname of it
pwd -P Print true full path, not path of locate file Search an index that the
symbolic link system builds periodically
sudo command Run command as root
Display a file
Navigating Directories
less file Display the contents of file one screenful at a time
cd dir Change the shell's current working directory spacebar Go forward one screenful
mkdir dir Create a new directory b Skip back one screenful
rmdir dir Remove the directory dir if dir is empty /word Search forward for word
Linux has a directory hierarchy starts at / (root directory). ?word Search backward for word
Directory separator is the slash (/).
q Quit less
Two dots (..) refers to the parent of a directory.
head file Display the first 10 lines of file
One dot (.) refers to the current directory.
tail file Display the last 10 lines of file
diff file1 file2 Print differences between two text files CTRL-B Move the cursor left
diff --color Print differences with color CTRL-F Move the cursor right
diff -y Print differences side by side CTRL-A Move the cursor to the beginning of the line
diff -c View differences in context mode CTRL-E Move the cursor to the end of the line
diff -w Ignore all white space CTRL-U Erase from cursor to beginning of line
CTRL-K Erase from cursor to end of line
diff gives the instructions on how to change the first file to make it
match the second file. CTRL-Y Paste erased text
< denotes lines in file1. > denotes lines in file2. CTRL-D Stop the current standard input entry from the terminal
Change command
LaR: Add the lines in range R of the second file after line L of the first Getting Online Help
file. man command Show manual page for command
FcT: Replace the lines in range F of the first file with lines in range T
man -k Search for a manual page by keyword
of the second file.
keyword
RdL: Delete the lines in range R from the first file so that both the
man n command Show manual page for command from section n
files sync up at line L.
Online Manual Sections
Environment and Shell Variables 1 User commands
stuff=blah Create a shell variable/Assign a value to a 2 System calls
variable 3 Higher-level Unix programming library docume‐
PATH=$PATH:dir Appends ":dir" to the end of PATH variable ntation
$STUFF Access a variable 4 Device interface and driver information
export STUFF Make $STUFF shell variable into an enviro‐ 5 File descriptions (system configuration files)
nment variable 6 Games
unset STUFF Delete variable STUFF 7 File formats, conventions, and encodings
env Prints environment variables (ASCII, suffixes, and so on)
8 System commands and servers
Shell variables are variables whose scope is in the current shell
session. Manual pages cover the essentials, but there are many more ways to
Environment variables are shell variables which has been exported. get online help. Try entering a command name followed by --help
Children processes get their own copy of the parent variables so they or -h to look for a certain option for a command
can never change the environment variables in their parent process.
Environment variables must be name=value pair.
Command path
PATH is environment variable that contains command path (list of
system directories that the shell searches when trying to locate a
command).
command > file Send the output of command to a file jobs -l List the active jobs with their status and pid (-l)
command >> file Append output to the file fg %n Move job that have job number n to the foreground
command < file Channel a file to a program's standard bg %n Move job that have job number n to the background
input command & Run command in background
command1 | command2 Send the standard output of command1
The ps command has many options. Options can be specified in
to the standard input of command2
three different styles—Unix, BSD, and GNU. Above commands use
command 2> file Redirect the standard error (2 is BSD style.
standard error stream ID)
command &> file Redirect the all output to file File Modes and Permissions
command 2>&1 Send standard error to the same place File's mode represents the file's permission and some extra inform‐
as standard output ation. There is 4 parts to the mode. First character is file type. The
rest contains the permissions, which break down into three sets:
Listing and Manipulating Processes user, group, other, in that order. Each set can contain four basic
representations:
ps List processes owned by root
r Means that the file is readable
ps x List all processes owned by you
w Means that the file is writable
ps ax List all processes on the system
x Means that the file is executable
ps u Include more detailed information
on processes - Means nothing