BASH cheatsheet

From eddynetweb's cesspit
Revision as of 21:05, 12 March 2017 by Eddynetweb (talk | contribs) (APT information.)
Jump to navigation Jump to search

Welcome to the BASH cheatsheet! Ever feel like you've just derped out and forgot some commands? This is what this is for.

Check the table of contents if you need help finding anything. Ctrl-F is also pretty helpful. :)

Common commands

Here you will find what I would consider the most common commands that sometimes people just forget when they boop out. I got you fam (it's actually for my sake, really).

Using APT

apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get autoclean

Working on this too. We'll get back to it later.

Using "alias"

An alias allows you to reference a command to another command on the system.

Say you'd like to set "ls -la" as the default "ls". You'd simply:

alias "ls -la"="ls"

General syntax:

To alias:

alias ["command"]=["origin"]

To unalias:

unalias ["command"]

Alias additions are not permanent and will generally disappear with a server reset. To combat this, you can save an alias change to ~/.bashrc in your local user directory.

Open ~/.bashrc in your favorite text editor and append the following:

alias ["command"]=["origin"]

Replacing whatever command with the appropriate areas.

See "man alias" for more details.

Using symlinks and hardlinks

Symbolic links allow for a person to create a sort of shortcut from a file or folder to another file or folder in another portion of your system.

There are two different types of links, hard links and symbolic links. If you notice, the name implies what they both do.

Hard links traditionally only work with files, but also physically link to the location on the drive itself by referencing the inode, not an abstract location. Symbolic links do reference such a abstract location, but as a result, when you move the destination link, it will generally become orphaned. Though, there are generally advantages and disadvantages with using either one.

- To make a symbolic link to a specific file or directory:

ln -s /original/path/ /link/path/


Yes, you can link directories as well as files, but because of the abstract nature of symlinks, any movement or deletion of the original file will lead to the symlink becoming orphaned/abandoned. Symlinks also do support linking from different volumes. However, they don't have the advantage of a physical inode location so any modification of the original file will likely break the symlink.

- To make a hard link to a specific file:

ln /original/file.path /link/file.path


You can't reference directories, but because hard links actually reference the inode, not the system, they are definite regardless of where you move the original file.

Deleting either is as simple as deleting the symlink file or directory made. Deleting said file/directory will not impact the data within the original file.

Anyways, that's about it for the scope of this document. If you have questions, remember to check the man docs for ln.

Using screen

Screen is basically a interactive shell which can act as a daemon in the background. It allows you to run shell instances, and also task them with certain commands.

I will eventually finish this, but for now:

screen -dmS AScreenName ApplicationRuntime

Be back later!?

Diskspace commands

Something soon?!