Super Essential Ubuntu Terminal Commands


Recently I started setting up Jenkins server in Ubuntu 16.04.3 machine. Check out this article if you are interested in the Ubuntu Jenkins master setup. I will start with the Ubuntu terminal commands that I found super essential.

Folders and files manipulation

man Display help for any command. Example: man ls

ls Lists current folder contents.

cd /var/lib/jenkins Change the current directory to /var/lib/jenkins. I found it very confusing initially that in Windows the paths are with back slash \, but in Ubuntu the paths are with forward slash /.

cp -a /foldertocopyfrom/file /foldertocopyto Copy files or folders. You should have permission for the destination folder.

sudo rm -f jenkins.log Delete the file jenkins.log.

sudo chown -R jenkins:jenkins /var/lib/jenkins Change the owner of the directory /var/lib/jenkins to user jenkins and group jenkins. R option will change the owner recursively for all folders and files that are inside the specified one. Useful when you receive Access Denied error.

sudo chmod -R 644 /var/foldername 777 code would mean that you give access to everyone to read and write in the folder, which is generally a very bad security practice. You can read more about permission codes here.

stat /var/lib/jenkins Display infomation about the owner and permissions for the file or folder.

Packages

sudo apt-get install jenkins Installs the package jenkins.

sudo apt-get install jenkins=2.89.3 Just put your preferred version in the place of 2.89.3.

sudo apt-get update Updates all packages.

sudo apt-get upgrade Upgrades all packages.

sudo apt-get upgrade jenkins=2.89.3 Upgrades package to a specified version.

jenkins --version See the Jenkins server version.

lsb_release -a Display the Ubuntu version.

whereis git Display git location

Jenkins Service

sudo service jenkins start Starts Jenkins service.

sudo service jenkins stop Stops Jenkins service.

sudo service jenkins restart Restarts Jenkins service.

sudo service jenkins status Shows Jenkins service status.

Monitoring

watch -n 5 free -m See used and free RAM memory.

df -h See hard disk usage.

sudo du -hxd 1 / 2>/dev/null | sort -hr Display hard disk usage sorted by folders size.

timedatectl Check date and time and if there the time is not correct use:

sudo timedatectl set-timezone EET Put your time zone in the place of EET.

sudo reboot When you see message “System restart required”, it is time to reboot your machine.

Summary

If you receive unexpected error when you are entering commands in the terminal, you could remember case sensitivity could be the issue. For many of the commands you may need root access. If this is the case put sudo (SuperUserDo) before the command.

I presented you Ubuntu terminal commands that I find most essential and useful. They are a great start for your Linux Ubuntu journey.