Kickin' It Old School with the Command Line

Kickin' It Old School with the Command Line

Beginners: Become comfortable with moving around, setting directory and file permissions, copying directories and files, moving directories and files, access servers with ssh, and more.

Intermediate: Expand your knowledge with tips for searching with grep, sharing sessions with screen, piping output, and more.

Advanced: Contribute with some of the voodoo that you do, and assist others during the workshop section.

634b37a53babc18a5bda19722d5b41a3?s=128

Rachel Baker

May 14, 2014
Tweet

Transcript

  1. Kickin’ It Old School by Rachel Baker with the Command

    Line
  2. Goals 1. Help beginners become more comfortable with using the

    command line tools.
 2. Expand the knowledge of intermediate command line users.
 3. Engage everyone in an educational (hopefully) workshop exercise of adding a user to a remote server, connecting to the remote server with your SSH key, and pairing with screen.
 4. Guilting other senior engineers into helping anyone stuck during the workshop portion.
  3. Essentials

  4. Little Help pwd Display current directory path.
 pwd : print

    working directory man : format and display manual pages man cd Display manual for cd command.
 man man Display manual for the man command.
  5. Moving Around cd : change working directory cd .. Move

    up one directory.
 cd ~ Move to the home directory.
 cd - Move to your last directory location.
 cd /usr/bin Move into the /usr/bin directory.
 cd / Move into the root directory. ! !
  6. Create folders mkdir wp Create a directory named “wp” within

    my current working directory.
 mkdir ~/wp Create a directory named “wp” within my home directory. mkdir : make a directory
  7. touch : create a file touch hiphop.txt Creates the empty

    file (0 bytes) hiphop.txt in the current working directory, if the file doesn’t already exist. touch hip.sh hop.sh Creates empty files hip.sh and hop.sh in the current working directory, if the file doesn’t already exist. touch -m 01021200 hip.sh Changes access and modification time for the file hip.sh to January 2nd at 12:00pm of the current year. Create Files
  8. List Contents ls : list contents of a directory ls

    List contents of the current directory.
 ls -a List all contents of the current directory.
 ls ~ -h List contents of your home directory with human- readable file sizes.
 
 ls ~ -ahl List all contents of your home directory with permissions and human-readable file sizes.
  9. Copy Contents cp : copy files and directories cp file.txt

    ~ Copy file.txt in current working directory to home directory. cp -R files/ /wp Copy everything in files directory from current working directory into /wp directory. The files directory itself is not included. cp -R files /wp Same as above, but the files directory itself is included. cp foo.txt bar.txt Copy all contents of foo.txt file to bar.txt file.
  10. Move Contents mv : move files and directories mv foo.txt

    bar.txt Renames foo.txt in current working directory to bar.txt.
 mv ~/wp / Move the wp directory and its contents from home into root.
 mv ~/wp/* / Move the contents of the wp directory from home into root. ! !
  11. Searching

  12. Locate Files find : walk a hierarchy find /wp -type

    f -name "*.php" Find all php files in the “wp” directory.
 find / -mmin -60 
 Find all files that were modified within the past hour. find / -size +50M Find all files that are larger than 50MB. find / -type d -name "wp-*"
 Find all directories that begin with “wp-“. find . -type f -exec chmod 644 {} ‘;’ Find all files within the current working directory and change their permissions to 644.
  13. Search Within grep : prints lines that are a pattern

    match grep define /srv/wp/wp-config.php Find all lines that contain the string “define” in the wp- config.php file.
 grep -n define /srv/wp/wp-config.php
 Find all lines that contain the string “define” in the wp- config.php file, and display the line number. grep -inr Error /var/log Recursively find anything in in the /var/log that contains the string “Error” (case insensitive) and display the line number.
  14. Streams

  15. ls -ahl /wp > root-files.txt Creates a file (root-files.txt) that

    contains the output of the ls command. If the file already exists it is overwritten. Streaming Output > : redirect stdout to a file >> : redirect and append stdout to a file ls -ahl /wp >> root-files.txt Creates a file (root-files.txt) that contains the output of the ls command. If the file already exists the output is appended.
  16. cp ~/wp /wp > cp-output.txt 2>&1 Creates a file (cp-output.txt)

    that contains the output or the error of the cp command. If the file already exists it is overwritten. Streaming Errors 2>&1 : send stderr to same location as stdout 2>> : redirect and append stderr to a file cp ~/wp /wp > /dev/null 2>> cp-errors.txt Ignore stdout from cp command, but create or append stderr to a file (cp-errors.txt).
  17. find . -type d | sed 's:[^-][^/]*/:--:g; s:^-: |:' Find

    directories within current working directory and modify the output stream to display a graphical tree of subdirectories. ! history | awk '{print $2}' | awk 'BEGIN {FS="|"} {print $1}’| sort | uniq - c | sort -rn | head -10 Get command history, sort output by second column (command), count the uniques, sort and display 10 most common results. Piping Output | : process and command chaining tool
  18. Workshop http://rachelbaker.me/tenup.html