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

Linux Tutorial Part 3: Basic Shell Skills 3

Linux Tutorial Part 2: Basic Linux Shell Skills 2

16. cat – catenates files

  • cat abc.txt – dumps the contents of ‘abc.txt’ to STDOUT
  • cat abc.txt def.txt dumps both files to STDOUT
  • cat abc.txt def.txt > abcdef.txt – creates new concatenated file
cat

17. mkdir – creates a new directory

18. cp – copies files

  • cp abc.txt testdir/
  • By default, ‘cp’ does NOT preserve the original modification time
  • cp -v def.txt testdir/

19. mv – moves files

  • mv abc.txt testdir/ – moves the file, preserving timestamp

20. rm – removes files/directories

  • rm abc.txt
  • rm -rf testdir – removes recursively and enforces

21. touch – creates blank file/updates timestamp

  • touch test.txt – will create a zero-byte file, if it doesn’t exist
  • touch def.txt – will update the timestamp
  • touch -t 201001011529 abcdef.txt – changes timestamp
rm,touch,ls

22. stat – reveals statistics of files

  • stat def.txt – reveals full attributes of the file

23. find – finds files using search patterns

  • find / -name ‘fstab’
  • Note: ‘find’ can search for fields returned by the ‘stat’ command

24. alias – returns/sets aliases for commands

  • alias – dumps current aliases
  • alias copy=’cp -v’
stat,find,alias

25. date – shows the current date and time.

 

Linux Tutorial Part 2: Basic Linux Shell Skills 2

Linux Tutorial Part 1: Basic Shell Skills 1

1. uname

‘uname -a’ returns :

  • OS – Linux
  • Fully Qualified Domain Name (FQDN)
  • Kernel version – 2.6.31…
  • 2.6 = major version
  • 31= minor version
  • 14 = Anything else after the minor version indicates that the kernel was patched by the distributor
  • Date and time that the kernel was compiled
uname

2. ifconfig

  • lists out all the network interfaces
  • useful to check or set the IP of an interface.
ifconfig

3. tty – reveals the current terminal
4. whoami – reveals the currently logged-in user
5. which – reveals where in the search path a program is located

6. echo – prints to the screen

  • echo $PATH – dumps the current path to STDOUT
  • echo $PWD – dumps the contents of the $PWD variable
  • echo $OLDPWD – dumps the most recently visited directory
tty,whoami, echo, $PATH

7. set – prints and optionally sets shell variables
8. clear – clears the screen or terminal
9. reset – resets the screen buffer
10. history – reveals your command history

  • !362 – executes the 362th command in our history
  • command history is maintained on a per-user basis via:
  • ~/.bash_history
  • ~ = users’s $HOME directory in the BASH shell
history

11. pwd – prints the working directory
12. cd – changes directory to desired directory

  • ‘cd ‘ with no options changes to the $HOME directory
  • ‘cd ~’ changes to the $HOME directory
  • ‘cd /’ changes to the root of the file system
  • ‘cd Desktop/’ changes us to the relative directory ‘Desktop’
  • ‘cd ..’ changes us one-level up in the directory tree
  • ‘cd ../..’ changes us two-levels up in the directory tree

13. Arrow keys (up and down) navigates through your command history
14. ls – lists files and directories

  • ls / – lists the contents of the ‘/’ mount point
  • ls -l – lists the contents of a directory in long format:
  • Includes: permissions, links, ownership, size, date, name
  • ls -ld /etc – lists properties of the directory ‘/etc’, NOT the contents of ‘/etc’
  • ls -ltr – sorts chronologically from older to newer (bottom)
  • ls –help – returns possible usage information
  • ls -a – reveals hidden files. e.g. ‘.bash_history’
  • files or directories prefixed with ‘.’ are hidden. e.g. ‘.bash_history’
pwd, ls , .bash_history

15. cat : to retrieve information from a file as in the os version in our case.

Output
Linux Tutorial Part 1: Basic Shell Skills 1