In BlogPost, Linux

Basic Linux Commands – Part 1

One of the things that I think helps new developers become more efficient is learning all the basic linux commands available to them. Being self-taught, I came from using a graphical user interface to extract any system information as well as navigate around the computer.

One of the things I learned is how much more quickly you can move if you’re able to be fluent with Linux terminal commands and shortcuts. This post introduces some of the basic linux commands and what they do.

I’ve broken it out into sections based on what each command does.

History & Date

1: history – The history command shows you all the commands you’ve previously issued. History also takes a numerical argument to show you the last “n” number of commands you issued. Hence, history 5 shows you the last 5 commands.

2: date – The date command prints the current date and time to the terminal.

3: cal – This cool command prints out the calendar to your window.

4: df – df displays the free disk space available on your system.

Navigations

5: pwd – This prints out the full path of the directory you are currently in.

6: cd – The cd command lets you change directories. Note it takes some arguments that can make your life easier.

a. cd – The dash after cd means to return to the last directory you were at.
b. cd .. The dot means go up one directory from the current directory.

Exploring the system

7: ls – This lists the contents of the current directory.

a. ls -a – I like passing the -a argument because you get to see all the directory entries that begin with a dot (e.g., .git).

8: file – This tells you what type of file something is. For example if I type file sample.rb (where sample.rb is a Ruby program), I get the following output:

9: less – Less is a handy utility for viewing large files. With larger input files, it can start up faster than a vi editor since it does not have to read the entire input file before starting.

10: symbolic links – A symbolic link is a special type of link that points to another file. Think of it as a Windows shortcut or alias. The syntax is ln -s source_file target_file.

Manipulating files and directories

11: cp – The copy command allows you to make copies of files. The syntax is cp file1 copy_of_file1.

12: mv – You can use this command to rename a file by doing mv file1_name file1_newname. You can also use it to move a file to another directory.

13: mkdir – This command is used to make a directory. Try mkdir new_directory.

14: rm – Be careful with this command as it lets you delete files.

Some more helpful terminal bits

15: man – This command lets you get descriptive help about any command. For example, if you type man less you will get a description of the less command and the arguments it takes.

16: tree utility – This is not a command, but more of a utility. It prints out the directory structure to your terminal as in the below. You can install it in MacOSx via a package manager like Homebrew or in Ubuntu via sudo apt-get install tree if it’s not on your system. It’s very helpful for visualizing your directory structure.

17: z utility – This is a cool utility that I found here. It lets you jump around to directories by allowing you type strings that closely match. For example, if I wanted to go to a directory called “elixir_rocks”, I might type z elixir. It’s really sped up my ability to navigate in between directories.

Summary

I hope you found these basic Linux commands helpful. Being more efficient on the command line can help you become a more productive programmer.

Recent Posts
elixir basics