wiki.allensmith.net

Personal "Rough Notes & Useful Links

User Tools

Site Tools


kb:linux:commandline

Linux Command Line Notes

  • The Command Line Interface is a text-only terminal based computer interface.
  • In a Graphical Desktop environment, a Terminal Emulator program simulates or provides this text-only interface.
Linux
Shell x.org
Command Line Interface Graphical Desktop
  • Virtual Terminals (VT) are text only console sessions that use the entire display and take ownership of the keyboard
  • On a Linux System, VT1 through VT7 are the expected Virtual Terminals
    • in a GUI using X, use CTRL-ALT-F1 through CTRL-ALT-F7 to access these
    • When already in a VT that is not using X:
      • then ALT-F1 through ALT-F7 will access VT1 through VT7
      • ALT-⇒ and ALT-⇐ will scroll Forward and Backward throgh the VT terminals
  • One Virtual Terminal (either VT1 or VT7) is reserved for the Graphical Environment
    • Ubuntu uses VT7, while CentOS/RHEL & openSUSE use VT1
On Mint 13 Xfce it was actually VT8 (ALT-F8) that returned to the Graphical Environment.
  • Most Commands have 3 possible parts
    • command → the name of the program to run
    • options → usually start with either one or two dashes
    • arguments → what the command operates on
  • Turning Off the Graphical Desktop
    • the Debian-based Linux Desktop Manager runs as a service → this service can be simply stopped
      • e.g. sudo service lightdm stop
    • the RPM-based Linux Desktop Manager is run directly by init when set to run level 5 → switching runlevel stops the desktop
      • e.g. sudo telinit 3
  • sudo provides as required admin privileges to the permitted users.
  • Rebooting and Shutting Down Linux
    • reboot → shutdown -r
    • halt and poweroff → shutdown -h
      • on a multi-user system shutdown could also be used as:
        $ sudo shutdown -h 10:00 "Shutting down for scheduled maintenance."
  • Locating Applications
    • Application programs can be found in /bin, /usr/bin, /sbin, /usr/sbin or under /opt
    • which utility →
    • whereis utility →
  • Directory Commands
    • pwdpresent working directory
    • cd ~ or cd → change to home directory
    • cd - →change to perevious directory
    • cd .. → change to parent directory
    • cd . → change to the current directory (does nothing)
    • remembering more than just the last directory visited
      • pushd . → would put the current the directory onto the directory stack
      • popd → use instead of cd - (which only remembers 1 level of previous directory)
      • dirs → display the list of directories in the directory stack
  • Absolute and Relative Paths
  • Filesystem Listing Commands
    • ls → list
    • ls -a → list all (show hidden files)
    • ls -l →
    • ls -li → i option adds the inode number
    • tree → displays a tree view of the filesystem
    • tree -d → view just the directories & suppress file names
  • Hard and Soft (Symbolic) Links
    • create a hard link for file2 from the existing file1
      $ ln file1 file2
    • crerate a symbolic link for file2 from the existing file1
      $ ln -s file1 file2
  • the 3 Standard File Streams
    • stdin → standard input → < or &0
    • stdout → standard output → > or 1> or &1
    • stderr → standard error → 2> or &2
  • Directing & Redirecting Standard Streams
    • $ some_command < input-file     # use input-file for stdin
    • $ some_command > output-file     # use output-file for stdout
    • $ some_command 2> error-file     # use error-file for stderr
    • $ some_command > all-output-file 2>&1     # use all-output-file for stdout and stderr
      $ some_command >& all-output-file     # shorthand to do same as the above
  • Pipes
    • | → output from the left goes to the input on the right
      • e.g. $ command1 | command2 | command3
    • The command on the right does not need to finish to start providing input to the left
  • Wildcards
    • ? → match any single character
    • * → match any string of characters
    • [set] → match any character of set (s or e or t)
    • [!set] → match any character not in set
  • Locating Files
    • locate command → search a (previously constructed) database of files and directories on your system
    • find command
      • -name → search for file (pattern) name
      • -iname → search for case insensitive file (pattern) name
      • -type d or -type f → search for only directories or files
      • -ctime → created time
      • -atime → accessed or last read time
      • -mtime → modified or last written time
      • -exec some_command → pip the results of find to some_command
  • File Viewing Commands
    • cat → output the file to stdout
    • tac → output the file last line first to stdout
    • less → view files output a screen at a time
    • tail → output the last 10 lines from the file
      • tail -n 25 or tail -25 → output the last 25 lines instead
    • head → output the first 10 lines (instead of the last 10 lines)
  • File Structure Commands
    • touch → used to create a file, or to change the date/time of a file
    • mkdir → create a directory
    • mv
    • rm
    • rmdir
    • PS1 variable → what the command prompt string is set to
kb/linux/commandline.txt · Last modified: 2016/01/13 20:35 (external edit)