Skip to content

Instantly share code, notes, and snippets.

@stanleycyang
Created April 6, 2015 04:45
Show Gist options
  • Select an option

  • Save stanleycyang/8f4768351a145c8b8470 to your computer and use it in GitHub Desktop.

Select an option

Save stanleycyang/8f4768351a145c8b8470 to your computer and use it in GitHub Desktop.
  1. Line tricks

    • Ctrl + a => Return to the start of the command you're typing
    • Ctrl + e => Go to the end of the command you're typing
    • Ctrl + u => Cut everything before the cursor to a special clipboard
    • Ctrl + k => Cut everything after the cursor to a special clipboard
    • Ctrl + y => Paste from the special clipboard that Ctrl + u and Ctrl + k
    • Ctrl + t => Swap the two characters before the cursor (you can actually use this to transport a character from the left to the right, try it!)
    • Ctrl + w => Delete the word / argument left of the cursor
    • Ctrl + l => Clear the screen
    • clear => Same as Ctrl + l
    • Option+Click on any part of the line to move
    • Ctrl + r: bck-i-search:
    • Ctrl + s: fwd-i-search:
    • history: Gives a list of commands
  2. Fun commands

    • cal: shows a calendar

    • date: shows current date

    • screencapture: Capture the current screen

        $ screencapture pic.png
      
    • file [filename]: show file type

    • zip: zip -r [zip name][filename]

    • unzip: unzip [zip name]

    • !!: Runs last command again.

        $ echo 'hello'
        $ !!
      
    • head: Show the beginning of a file

    • tail: Show the end of a file

    • less: show a file on the screen

        less [filename]
      
    • nano: Text editor

    • vi: Text editor

    • vim: Text editor

    • top: See all running processes

    • kill: Select a process number and kill task

    • ps: Process status. Check the status of the file

    • grep: Finds text in a file

        $ cd Desktop
        $ touch foo.txt
        $ subl foo.txt
        // Write lorem ipsum, then..
        $ grep Lorem foo.txt
        
        // Use the -i to make it case insensitive
        $ grep -i lorem foo.txt
        // Use the -w to match the whole word
        $ grep -i -w lorem foo.txt
        
        // In sublime, add in a second line of hi
        // use -v to show everything BUT the line that contains the word
        $ grep -v lorem foo.txt
        // Use wildcard to match with the word
        $ grep "Lore." foo.txt // single character
        $ grep "ven*" foo.txt // group
      
  3. Navigation

    • cd . cd .. cd/
    • relative and absolute paths
      • . is current directory
      • .. is a directory above
      • / is root directory
      • ~ is user's home directory
    • pushd changes to another directory and saves current location to array
    • popd goes back to the pushed locations
    • open . (in the finder), open -R
    • ls -a -l
      • -a prints hidden files and directories
      • -l prints detailed view
    1. working with files
    • touch, nano
    • rm (-r), cp, mv
    • mkdir, rmdir
    • hard links
      • ln
    • soft links
      • ln -s

    An inode is a data structure on a filesystem on Linux and other Unix-like operating systems that stores all the information about a file except its name and its actual data. A data structure is a way of storing data so that it can be used efficiently.

###Hard vs. Symbolic link

A hardlink isn't a pointer to a file, it's a directory entry (a file) pointing to the same inode. Even if you change the name of the other file, a hardlink still points to the file. If you replace the other file with a new version (by copying it), a hardlink will not point to the new file. You can only have hardlinks within the same filesystem. With hardlinks you don't have concept of the original files and links, all are equal (think of it as a reference to an object). It's a very low level concept.

On the other hand, a symlink is actually pointing to another path (a file name); it resolves the name of the file each time you access it through the symlink. If you move the file, the symlink will not follow. If you replace the file with another one, keeping the name, the symlink will point to the new file. Symlinks can span filesystems. With symlinks you have very clear distinction between the actual file and symlink, which stores no info beside the path about the file it points to.

Hard vs. Soft Link

###Changing permissions

ownership

  • chmod Change access permissions
  • Chmod

###Alias

alias r='ls -r'

Now, r command runs ls -r

###Shutdown

  • shutdown: Shut down the computer. We'll put it to sleep mode

      sudo shutdown -s now
    
  • halt: stop and restart the operating system

      $ sudo halt
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment