Introduction to the Linux command line
If you have come from Windows, the Linux command line can initially look familiar and completely different at the same time. Helpful!
Many Linux systems use Bash or another Unix-like shell. The exact shell can vary, but the basic ideas transfer rather well.
Linux paths
Linux paths use forward slashes. The root of the filesystem is /, while ~ is commonly used to represent your home directory.
Linux filenames are generally case-sensitive. Game.py and game.py can therefore be different files.
Useful commands
pwd: show your current directory.ls: list files.cd: change directory.mkdir: create a directory.cp: copy files.mv: move or rename files.rm: remove files.cat: output a file.less: read longer output a page at a time.grep: search text.
Permissions
Linux tracks permissions such as whether a file may be read, written or executed. The chmod command changes permissions. Do not start throwing chmod 777 at everything because a random forum post told you to. Understand the permissions you actually need.
sudo
sudo can run a command with elevated privileges when your system is configured to allow it. That makes it useful and also gives you more opportunity to break things. Read a command before putting sudo in front of it.
Package managers
Linux distributions use package managers to install software. The exact command depends on your distribution, so follow its documentation rather than assuming every Linux machine uses the same one.
Where next?
Learn enough commands to move around, inspect files and run your development tools. You can learn shell scripting later if you actually need it. One terminal-shaped mountain at a time.
Linux is case-sensitive
This is an easy one to forget if you have mainly used Windows.
On Linux, Documents and documents can be two different names. If a command says a file does not exist, check the capital letters before assuming the universe has eaten it.
Your home directory
The tilde, ~, is commonly used to represent your home directory.
cd ~
That gives you a handy way to get home without typing the entire path.
Be careful with sudo
sudo lets an authorised user run a command with elevated privileges. You will see it in an enormous number of Linux instructions.
Do not get into the habit of putting sudo in front of a command just because the first attempt failed. Find out why the command needs extra privileges first. Giving a command more power does not make a bad command better. It just makes the bad command more enthusiastic.
Deleting from the command line
Commands such as rm can remove files without sending them to a nice friendly recycle bin. Before pressing Enter on a destructive command, read it again.
This is especially important when copying commands from the web. Understand what a command does before running it.
Have a go
Make a temporary directory in your home folder. Move into it, create another directory, list the contents, move back to your home directory and remove the temporary directory when you're finished.
Further reading and external resources
Want to dig into this a bit more? These are good places to go next. If anything here ever disagrees with the official documentation, trust the official documentation.
Previous: Introduction to the Windows command line | Next: Environment variables and PATH
Image Description