Chapter 3 Cheat Sheet

Shells

  • echo $SHELL
    • Displays your current shell.
  • cat /etc/shells
    • Displays all available shells.
  • chsh
    • Changes your shell.
  • chsh -s <shell> <user>
    • As root, changes specified user's shell.
    • Can also use usermod -s <shell> <user>

I/O Redirection

    • redirect stdout (same as 1>).
  • 2> 
    • redirect stderr.
  • &> 
    • redirect both stdout and stderr (same as 2>&1).
    • &> does not work when piping, must use 2>&1.
  • >> 
    • append to file; > overwrites contents.
  • /dev/null 
    • the garbage disposal.
  •  < 
    • redirect input from file.
  • |
    • Pipe output from command to another command.

File and Directory Concepts

  • pwd
    • Prints the current working directory. 
  • cd ~/folder
    • Changes directory to folder in your home directory.
  • cd ~<user>
    • Changes to user's home directory.
  • cd -
    • Changes to previous working directory.

File Lists and ls

  • ls -l
    • Long listing of the contents in a directory.
  • ls -ld /directory
    • Display long listing information about directory, not contents.
  • ls -lh
    • Display file sizes in human readable format.
  • ls -lrt
    • Reverse sort files by time modified (newest at bottom)
  • ls -a
    • Show hidden files and directories.
  • ls -i
    • Shows the inode number.
  • ls -F
    • Display a / after each directory, * after each executable file, and a @ after each symbolic link.

File Creation Commands

  • touch file
    • Creates the file. If file exists, updates last access date.
  • cp file1 file2
    • Makes a copy of file1 called file2.
  • mv file1 file2 or mv directory1 directory2
    • Renames file1 to file2.
  • ln sourcefile linkfile
    • Creates a hard link from sourcefile to linkfile.
  • ln -s sourcefile linkfile
    • Creates a soft link from sourcefile to linkfile.

Directory Creation and Deletion

  • mkdir test
    • mkdir -p /test1/test2/test3
  • rmdir test
    • deletes directory only if empty.
    • rmdir -p /test1/test2/test3
  • rm -rf test1
    • Deletes directory and all subdirectories.

Alias

  • Typing alias alone will show aliases.
  • alias rm='mv -t ~/.Trash'
    • Now when you type rm <file>, the file is move to trash rather than deleted.

Wildcards

  • *
    • matches 0 or more characters.
    • ls ab* will return abcdefg, abc, abd, and ab.
  • ?
    • Matches one character.
    • ls ab? will return abc and abd, but not abcdefg or ab.
  • []
    •  Matches a range.
    • ls ab[123] will match ab1, ab2, and ab3, but not ab123.
    • ls ab[A-C] will match abA, abB, and abC.

File Searches

  • find <where> -name <what>
    • finds what in where.
    • -iname for case insensitive search.
  • locate <what>
    • Searches the locate database for what.
    • Faster than find, but since database is only updated every 24 hours, not as accurate.
    • Update database by typing /etc/cron.daily/mlocate.cron

Commands to Process Text Streams

  • cat
    • cat /etc/passwd
  • less
    • less /var/log/messages
  • head and tail
    • head -n20 /etc/passwd
    • tail -f /var/log/secure
  • sort
    • sort /etc/passwd
  • grep and egrep
    • grep <"what"> <where>
    • egrep supports +, ?, |, (, and ).
  • diff
    • diff file1 file2
  • wc
    • wc file
    • wc -l file
  • sed
    •  sed 's/Windows/Linux' file > newfile
  • awk
    • awk '/mike/ {print $1}' /etc/passwd

vi

Documentation

  • command --help (or command by itself).
  • man <command>
  • whatis nfs (show all man pages associated with nfs).
  • apropos nfs (show all man pages related to nfs).
  • apropos and whatis both search the whatis database, which is updated every 24 hours. To update database manually, run /etc/cron.daily/makewhatis.cron.
  • Type whatis smbpasswd and notice the output. A man 5 smbpasswd reads the man page related to the file, a man 8 smbpasswd reads the man page associated with the actual command.
  • /usr/share/doc
  • info bash
    • For a full list of info manuals: ls /usr/share/info.

Network Daemons

  • service network start/stop/status
  • service NetworkManager start/stop/status
  • chkconfig network off/on
  • chkconfig NetworkManager off/on

Network Configuration Files

  • /etc/sysconfig/network
    • Turn networking on/off.
    • Set hostname.
    • Set the gateway. The device configuration file and dhclient both override this directive.
  • /etc/sysconfig/ifcfg-<device>
    • Configure network adapter.
  • /etc/hosts
    • Map IPs to hostnames on the local network.
  • /etc/nsswitch.conf
    • Tells what database to look at and in what order.
  • /etc/resolv.conf
    • Defines which name servers to use.

The ip command

  • ip addr show <device> 
    • shows devices configuration (e.g., ip address)
  • ip link set <device> down 
    • takes the device offline.
  • ip address add <IP> dev <device> 
    • configures the IP address for device.
  • ip addr add <IP/mask> broadcast <IP> dev <device> 
    • configures IP and broadcast.
  • ip addr del <IP/bits> dev <device> 
    • deletes IP address for device.
  • ip addr <IP/mask> dev <device> label <device>:1 
    • creates an alias for device.
  • ip route show
  • ip route add <IP/mask> dev<device>
  • ip route add default via <IP>
  • ip route delete <IP/mask> dev <device>
  • ip neigh add <IP> lladdr <MAC> nud permanent dev <device> 
    • adds an entry to the ARP table for device.
  • ip link set dev <device> arp off 
    • turns arp off for device.

Network Configuration Tools

  • system-config-network (command line)
  • nm-connection-editor (GUI)

Comments

Popular posts from this blog

Introduction