Many operating systems such as a Linux are considered ‘Unix-like’ and therefore it’s more than likely that you’ll have to know some basic UNIX commands in order to be proficient at using the command line.
Assuming you are a complete beginner, let’s start with a few commands to get you underway.
ls
– Use ls to list the files in the current directory.
cd
– Use cd to change directory.
$ cd desktop # Changes directory to desktop
mkdir
– Use mkdir to make a directory.
$ mkdir test-project # Makes a 'test-project' directory.
rmdir
– Use rmdir to remove a directory. Note that the directory must be empty to use this command.
$ rmdir test-project # Deletes the 'test-project' directory.
cp
– Use cp to copy a file.
$ cp file1 file1.bak # Copies file1 into a file1.bak backup.
rm
– Use rm to remove a file.
$ rm index.html # Removes the 'index.html' file.
mv
– Use mv to move or rename a file.
$ mv old.html new.html # Moves and renames 'old.html' to 'new.html'.
grep
– Use grep to search for a specific string within files.
$ grep "some string" *
chmod
– Use chmod to change file permissions.
$ chmod 644 index.html # Changes the permissions of index.html to read and write.
chown
– Use chown to change file ownership of a file. User and group ownership can be changed.
$ chown www-data:usergroup index.html # Changes the ownership to the 'www-data' user and the 'usergroup' group.
zip
– Use zip to compress a file or a directory. Note that to compress a directory, pass in -r
.
$ zip compressed.zip file1.html # Compresses 'file1.html' into a 'compressed.zip' file.
$ zip -r compressed.zip dir1 # Compress the 'dir1' directory into a 'compressed.zip' file.
unzip
– Use unzip to extract a compressed file.
$ unzip compressed.zip
logout
or exit
– Use logout or exit to quit a UNIX shell.