BASH cheatsheet

From eddynetweb's cesspit
Jump to: navigation, 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

This one-liner will upgrade the packages and system to the latest revision of whatever distro you're running.

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

For Debian users: You can also call for backport packages in Debian, which in this instance would allow you to fetch the next revision of packages within the next repo. You can setup backports by following this guide: Debian Jessie repos.

Regardless, in order to fetch a backport package, use the following:

apt-get -t jessie-backports install "package"

Backports is useful in this instance because it also is compatible with upgrades for future Debian updates.

More stuff soon!


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/

Limitations:

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

Limitations:

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.

To create a basic screen session, you'd use the following:

screen -dmS AScreenName ApplicationRuntime

"ApplicationRuntime" is whatever you're running in the instance of creating a screen. It's not necessary to immediately specify though, so you can create the screen session without "ApplicationRuntime," then run the application and exit through "Ctrl-A."

There's more!

Diskspace commands

Something soon?!