Linux Tutorial Part 3: Basic Shell Skills 3


26. Input redirection ‘<‘:

  • cat < abc.txt
  • Use input redirection when program does NOT default to file as input

27. Output redirection ‘>’:

  • cat abc.txt > new.txt
  • Default nature is to:
  • Clobber the target file
  • Populate with information from input stream

28. Append redirection ‘>>’:

  • cat abc.txt >> new.txt – creates ‘new.txt’ if it doesn’t exist, or appends if it does
  • cat def.txt >> new.txt

29. Pipes ‘|’:

  • Connects the output stream of one command to the input stream of a subsequent command
  • cat abc.txt | sort
  • cat abc.txt def.txt | sort
  • cat def.txt abc.txt | sort | grep d

30. Command Chaining

  • Permits the execution of multiple commands in sequence
  • Permits execution based on the success or failure of a previous command
  • cat abc.txt ; ls -l – this runs first command, then second command without regards for exit status of the first command
  • cat def.txt && ls -l – this runs second command, if first command is successful
  • cat abcd.txt && ls -l
  • 4. cat abc.txt || ls -l – this runs second command, if first command fails

31. more|less – paginators, which display text one-page at a time

  • more /etc/fstab
  • less 1thousand.txt

32. seq – echoes a sequence of numbers

  • seq 1000 > thousand.txt – creates a file with numbers 1-1000

33. su – switches users

  • su – with no options attempts to log in as ‘root’

34.  head – displays opening lines of text files

  • head /var/log/messages

35. tail – displays the closing lines of text files

  • tail /var/log/messages

36. exit – logs out of current user session

37. wc – counts words and optionally lines of text files

  • wc -l /var/log/messages
  • wc -l def.txt

38. file – determines file type

  • file /var/log/messages

Advertisements
Linux Tutorial Part 3: Basic Shell Skills 3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s