file viewing | more - less advanced
less - more advanced |
displays the first 10 lines of file | head file_name |
displays last 10 lines of file | tail file_name |
variable that defines the default editor | EDITOR |
displays currently working directory | pwd |
long listing
displays rights, owners etc | ls -l |
changes directory to most recent one
changes directory to home | cd -
cd ~ |
updates file timestamps
if file does not exist it is created | touch file_name |
creates multilevel directory | mkdir -p sub1/sub2/sub3 |
creates a symlink | ln -s source_file symbolic_link |
removes file
removes non empty directory
removes empty directory | rm file_name
rm -R dir_name
rmdir dir_name |
command used to transfer files and dierctories to local or remote destinations | rsync [options] SOURCE DESTINATION |
compares files line by line
displays results side by side | diff old_file new_file > file_patch
diff -y
Symbols:
< lines missing in first
> lines missing in second
| lines that differ |
reads the changes that need to be applied from source file and then applies the changes | patch old_file new_file.patch |
compressing files
decompressing files | gzip file_name
gunzip file_name.gz
bzip2 file_name
bunzip2 file_name.bz2
xz file_name
unxz file_name.xz |
creates a single file that is a concatenation of files given as arguments | tarball creation:
tar -cvf tarball.tar file_1 file_2
tarball extraction:
tar -xvf tarball.tar
-c create
-x extract
-v verbose mode
-f specifies name
leaves source files untouched
doesnt create extention .tar auomatically |
finding files and performing operations on them | fin [where to look for] [conditions while looking for] [what to do] |
What is a stream | communcation channel for transfering ordered bytes |
overwrites somefile with output
overwrites somefile with output and error | ls > somefile
ls &> somefile
ls > & somefile |
appends output to somefile
appends output and errors to some file | ls >> somefile
ls &>> somefile |
gets input frome some file
content of somefile will be displayed | ls < somefile |
What standard streams are there? | stdin (0)
stdout (1)
stderr (2) |
redirection to stderr and stdout | 2>&1
or:
>& |
redirecting to "black hole" file | >/dev/null |
redirecting to /dev/null and ignoring stderr | 2>/dev/null |
what are filters | filters are commands that take input from stdin if there are no filenames given
examples: sort, grep |
what are pipes | pipes allow for redirecting stdout of one command to stdin of another
symbol:
|
if second command is a filter it processes stdout of preceding command |
how to perform command substitution | `command`
content is replaced with stdout of the command
example:
echo my name is `whoami`
my name is hania |
counting lines, words, characters | wc [-l|-w|-c] filename
can be used in pipelining
example:
env | wc -l |
sorting | sort filename
can be used in pipelining
example:
env | sort |
what is generic regular expression parser | grep is used for searching and extracting lines form file that match some regular expression
grep [options] patter file_name
popular options:
-i -ignore case
-v -invert selection
zgrep allows for grepping over compressed files |