Linux Commands that you need to know as a Software Engineer! - Episode 1

·

4 min read

Linux Commands that you need to know as a Software Engineer! - Episode 1

Hi! Linux is an OSS(Open-source Software) that's has been used for ages by Engineers, Developers, Administrators for a Long time in order to maintain servers, computers. As a Software Engineer, it might be difficult to get hang of every Linux command available out there. But the following commands are useful for me and I hope they are useful for you too:) This is the first blog for this series and I'm gonna add more blogs soon.

Basic commands

  • man - This is the most basic command yet powerful. It is used to display the usage of every command that is there in the manual.

man command_name

  • man man

image.png

  • mkdir - used to create directory.

    mkdir dirName

  • rmdir - used to remove directory.

rmdir dirName (removes only empty directories) Use -rf flag to remove whole content in the dir

e33815fb2f3fadd73cf782eaa8fc69fddcf33a8b.jpeg

  • pwd - returns the path of the present working directory.

pwd

  • ls - Lists all the directories, files in the current directory

ls ( flag -l to display permissions, filenames, author name, memory,data Created, flag --a to display hidden files and folder names, -S is used to display after sorting the directories based on the size in decreasing order)

  • you can use regex patterns to display whatever file type you want eg: ls *.json (displays all json files in the current directory)

cat text.txt

touch createfile.txt

vi createfileusingvim.txt

User Permissions in Linux

  • You have to remember these three types of roles that exist for any file/directory.

-u (users) -g (group) -o (others)

  • And there are three types of operations that are there for all these files

read write execute

  • chmod used to change permissions

chmod -g+wx filename (changes group permission of a file to write and execute)

  • changing owner and grp owner

chown ownernameyouwanttoupdate:grouptoupdate filename

  • whoami - shows the current user

sudo useradd/groupadd username (as the name says adding a new user/group)

sudo userdel/groupdel username

  • to change user password /create new passed.

su passwd username (after this enter password)

  • display all users

awk -F: '{ print $1 }' /etc/passwd

  • su -username (to switch to other user)

  • permissions (775) user-7(4(read)+2(write)+1(exec)) group -7 others-5(read+exec)

processes

  • top - If you want to know what processes are currently running

top

  • kill processName - kills the process :(
  • ps -ef (displays all running processes)
  • ps -aux (all processes are displayed)

Environment variables (creation and display)

  • printenv (displays all env variables)
  • echo $varName

displays the value of that env variable

  • echo $OLDPWD (displays prev working directory path)
  • echo $PWD (displays pwd path)
  • echo $USERNAME (displays current username)
  • echo $HOSTNAME (displays host name)

grep command overview

you-said-that-you-have-5-yrs-experience-using-unix-commands-the-fact-that-you-asked-me-how-to-use-a-.jpg

Just like this meme. grep is the most useful command for software engineers yet has many different applications. grep is used to search for different patterns of strings present in the contents of the files. Let us discuss a few here:)

  • grep searchString text1.txt

it searches the string in the text and highlights it. (flag -i is used to make the search case insensitive, flag -c gives the count of string in different lines, flag -n gives the string along with the line in which they occur)

  • grep -r searchString dir (does a recursive search in the whole directory)
  • grep -r string / (search in root dir)

find command

  • find pathname (find is used to search for a particular dirName / pathName in any directory)

find .*txt (displays all txt files in the current dir)

find searchString / (finds in root dir)

find . -name fileName.ext

find -perm 775 (finds all files having 775 as permission)

remote access (ssh)

  • ssh root@ip / ssh IP (used to login to the remote server)

copy

  • cp source destination

(flag -R used to copy whole directory, flag -i goes to interactive mode (much safe because it asks when you are trying to modify existing ones)

  • cp Desktop/a.png (copy from destination to pwd)
  • scp sourcepath remote_hostname@10.10.0.2:/remote/directory (secure copy from one server to remote server)

The images used are from Google Search. I'm not the owner of them btw.