Basic Commands¶
echo
cat
ls [-la] # list files in the present directory
chmod [+x] file
mkdir # make new directories
cd # change the directory
pwd # present working directory
cp path_from path_to # copy
mv path_from path_to
rm path # delect files
rmdir # delete empty directories
touch file_name # create empty file
tr ' ' '\n' # translate ' ' into '\n'
sort [-nr] # sort [numerically, reversely]
uniq [-c] # unique [with number of occurance]
head # first 10 lines
grep # regular expression
ps ax|e # processes
cut
date
who
man
kill
fg
bg
jobs
free
uptime
.. # parent directory
. # current directory
> # redirect the output, destination is overwritten
>> # redirect the output and append to the destination
< # read input from file
2> # redirect stderr to a file
| # pipe
ls -l | less
Bash Scripting¶
use ; to separate command in the same line
$(command)
export varaible_name=value # no space around =, local if without export echo $variable_name
*? # globs
$? exit status of commands, 0 if True if grep "126.0.0.1" /etc/hosts; then echo "something" else echo "something else" fi
test -n "$PATH" # return 0 if True, 1 if False if [ -n "$PATH" ]; then echo "something"; fi
while [ $n -le 5 ]; do some command Done
$1 # first argument after command
for fruit in a b c; do echo $fruit done
name="abs" "$name.html"