Basic Linux Commands
Bread and Butter
grep
Stands for "global regular expression print," processes text line by line and prints any lines which match a specified pattern.
Directory commands
Print working directory
pwd
Change directory
cd
Change directory to your home directory
cd ~
Go back to previous directory
cd -
Go to the parent directory
cd ../
List files in directory
ls
ls -la
shows all the files and directories along with the permissions
File commands
Copy
cp
Remove file(s)
rm
Make directory
mkdir
Output content of file
cat
Output file one page at a time
more
Output the file one page at a time with page up and down navigation (this is not available in more)
less
Output the first ten lines of a file
head
Output the last part of a file
tail
Searching for files
Find
A slow but thorough search. You can search for files recursively and with regex!
find filename
Locate
Quickly locates a file but relies heavily on an internal database. To update the internal database first
sudo updatedb
#Then you can run
locate filename
Which
The command will output the path of the binary that you are looking for by searching through the directories that are defined in your $PATH variable.
which bash
# Usually outputs: /bin/bash
User Management
To add a new user
sudo adduser NameOfUser
On other distros it is
sudo useradd nameOfUser
To add a user to the Sudo users group
sudo adduser NameOfUser sudo
If you don't have an interactive shell you will have to use this command syntax to add the user into the /etc/sudoers text file
sudo echo "username ALL=(ALL) ALL" >> /etc/sudoers
To delete a user
sudo userdel NameOfUser
Checks which users are in the Sudo users group
cat /etc/group | grep sudo
Switches user to Sudo in the Terminal
su sudo
Process command
This command will display information on the running processes, -a
stands for all processes; -u
stands for all processes by all users; -x
stands for all processes that don't run a tty.
sudo ps -aux
Installing and Uninstalling Packages
To install a package you have to do the following:
#This command will install openvas using apt
sudo apt-get install openvas
#This command will install a package using a .deb file.
sudo dpkg -i /root/Downloads/openvas.deb
To uninstall a package you have to do the following:
# This will show all installed packages.
dpkg --list
#Find the name of your package/program/application that you want to uninstall then move on to the command below.
sudo apt-get --purge remove NameOfPackage
#This will uninstall any dependencies that was installed with the package.
sudo apt-get autoremove
Commands for services
systemctl can be used to enable or disable services at boot up, check the status of a service or restart the service. To enable a service to start up at boot.
sudo systemctl enable vncserver-x11-serviced.service
sudo systemctl enable vncserver-virtuald.service
To disable a service from starting up at boot.
sudo systemctl disable vncserver-x11-serviced.service
sudo systemctl disable vncserver-virtuald.service
To start, stop or check the status of a service.
sudo systemctl start vncserver-x11-serviced.service
sudo systemctl start vncserver-virtuald.service
sudo systemctl stop vncserver-x11-serviced.service
sudo systemctl stop vncserver-virtuald.service
Init.d does the same thing, it is just a wrapper around systemctl.
sudo /etc/init.d/vncserver-virtuald.service start
sudo /etc/init.d/vncserver-virtuald.service stop
sudo /etc/init.d/vncserver-virtuald.service status