BASIC LINUX COMMANDS
Linux commands are case sensitive hence you need to be careful about what you are keying in
1. ls –
2. cd /var/log –
-Change the current directory. The forward slash is to be used in Linux. The example is a Linux directory that comes with all versions of Linux.
-When you use ls –I you will be able to see more details of the contents in the directory It will
-list down the
• The owner of the file
• The group associated with the file
• The size of the file
• The time stamp
• The name of the file
-Find text in a file. The grep command searches through many files at a time to find a piece
of text you are looking for.
-grep PATTERN [FILE]
-grep failed transaction.log
-The above command will find all of the words in the files that matched the word ‘failed’
4. su / sudo command –
5. pwd – Print Working Directory
One way to identify the directory you are working in is the
pwd command
It displays the current working directory path and is useful when directory changes are often
$ pwd
6. passwd –
Though looks similar to the pwd command the role it plays is different.
This command is used to change the user account password.
You could change your password or the password of other users. Note that the
normal system users may only change their own password, while root may modify the password for any
account.
passwd [username] - changes the password for the user
$ whoami admin //will print your username. $ passwd admin // change ‘admin’
to yours |
7. mv - Move a file
To move a file or rename a file you would use the mv command.
Here the file name gets changed from first.txt to second.txt.
Type ls to view the change
$ touch first.txt
$ ls
$ mv first.txt second.txt
8. cp – Copy a file
cp source file destination file. In case you need a copy of the file second.txt in the same directory you have to use the cp command
$ cp second.txt third.txt
$ ls
You can use ls – l to see the new file created. The two files will be exactly of the same size.
9. mkdir – to make a directory.
mkdir
[directory name] if you would like to create a directory in the
name ‘unimap’ type mkdir unimap
$ mkdir unimap
10. rm –
This command is used to remove files in a directory or the
directory itself. A directory cannot be removed if it is not empty.
rm
[name of the file] rm –r
removes all the contents in a directory and the directory as well.
$ ls
$ rm os_file
$ rm -r os_file
$ ls -l
11. chmod –
This command is used to change mode of a file system object. Files can have r – read, w- write and x-execute permissions..
rm [name of the file] rm –r removes all the contents in a directory and the directory as well.
a-w is used to make all users have no write access to file and u+x is used to make the owner execute the file labeled.
12.chown
chown owner_name file_name
changing ownership to
root use “sudo” before syntax. $ sudo chown root script.sh assuming user is
mitren03 :
$ sudo chown root
script.sh
13.
cat -
The cat command (short for “concatenate “) is one of the most frequently used commands in Linux. cat command allows you to create single or multiple files, view contents of file, concatenate files and redirect output in terminal or files.
Output will show the entire contents of the file(s).
14. echo –
This command is used to
display a text or a string to the standard output or a file.
$ echo “This is an article on basic linux
commands”
This is an article on basic
linux commands.
The echo –e option acts as an interpretation of escape characters that are back-slashed.
15. wc –
The wc (word count) command in Linux operating system is
used to find out the number of new lines, word count, byte and characters count
in a file specified by the file arguments.
wc [options] filenames.
Shows the output as - 120 readme.txt
· wc -l : Prints the number of lines in a file
wc -w : prints the number of words in a file.
·
wc
-c : Displays the count of bytes in a file.
·
wc
-m : prints the count of characters from a file.
·
wc
-L : prints only the length of the longest line in a file.
16. man –
This command is used to view the on-line reference manual
pages for commands/programs.
17.history
$ history
This command was used to show previously used commands and to get information about commands executed by user before.
18.clear
This command was used to clear the terminal screen, the terminal after the command was used:
19.apt-get
apt -get command is a powerful and free front-end package manager for Debian/Ubuntu system that is used to install new software packages, remove available software packages, upgrade existing software packages as well as upgrade the entire operating system. apt – stands for advanced packaging tool.
using command : $ apt-get
using sudo apt-get update, in other words, it doesn't actually install any new version of software. Instead, it updates the package lists for upgrade that need new upgrades as well as new packages that have come to the repositories.
20.reboot
$ reboot
This command may be used to halt, power-off or reboot a system as follows.