UNIX Commands Ls – List Contents of a Directory

UNIX Commands Ls – List Contents of a Directory

UNIX Commands ls – list contents of a directory pwd – display current directory cd – change to directory (cd test) cp – copy file (cp from_file to_file) mv – move file (mv from_file to_file) rm – delete file (rm test1) mkdir – make directory (mkdir test) rmdir – remove directory (rmdir test) man – help for given command (man cp) cat – display contents of file more – display contents of file with page breaks (next page with Space key) head – display top of file tail – display end of file grep – search for pattern in file (grep “pattern“ test1) vi – edit file (more on this later) wc – count number of lines, words, characters in a file (wc -l file.txt) cut – cut out parts of file (cut -f 2 -d : file.txt) du – report disk usage (du -h) df – report file systems and their usage (df -h) chmod – change permissions of a file (chmod a+r file.txt) ln – create a link to a file (ln -s ~/bin/prog.exe prog1.exe) Wildcards: * - matches any number of letters incl. none ? - matches any single character [] - encloses set of characters that can match the single given position - used within [] denotes range of characters ~ - followed by user name = home directory (~mcuma) Command redirection: > redirect to a new file (cat test1 > test3) >> - append to a (new or existing) file (cat test2 >> test3) | - pipe – redirect command output to another command Vi basic reference i – insert I – insert at start of line a – append A – append at end of line o – enter insert mode on a new line r – replace single letter R – replace mode x – delete letter dd – delete line D – delete from cursor to end of line u – undo G – move to end of file #G – move to line # ^ - move to start of line $ - move to end of line ctrl-f – move page forward ctrl-b – move page back :w – save current file :w filename – save file to new file :q – quit vi :wq – save and quit :q! - quit without saving :w! - force save :n filename – open another file /pattern – search forward for pattern ? - search backward for pattern; subsequent entry of / or ? searches for next occurence of pattern :s/old_text/new_text – replace next occurence on current line :s/old_text/new_text/g – replace all occurence on current line :%s/old_text/new_text/g – replace all occurences in the whole file Scripting Loops foreach VAR ($VARLIST) … end while (condition) … end break – break out of the loop continue – skip to next loop iteration Conditions if (condition) then … else … endif switch (string) case pattern1: … breaksw default: commands... breaksw endsw Conditional expressions ==, !=, >, < ,&& ,|| - equal, not equal, larger, smaller than, and, or - like in C language !($?var) – true if variable does not exist =~ - if the right hand side matches a pattern, (i.e., similar to filename matching, with asterisks and question marks.) the condition is true. !~ - if the right hand side doesn't match a pattern, the condition is true. -d $var - true if the file is a directory. -e $var - true if the file exists. -f $var - true if the file is a file. (I.e., not a directory) -o $var - true if the file is owned by the user. -r $var - true if the user has read access. -w $var - true if the user has write access. -x $var - true if the user has execute access. -z $var - true if the file is zero-length. Shell variables variables are denoted with $ - echo $VAR strings defined by set – set VAR=(1 2 3 4) numbers defined by @ - @i = 1 conversion of string to number with expr - @i = `expr $number + 0`.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us