Introduction to Linux Command Line
Whenever it comes to some serious stuff like using a cluster or open-source software like OpenFOAM people are faced with the famous Linux command line. It was scary at the first sight but later on, when you get used to him, he will be your best friend.
Here some basic commands that it as a good start point
When you open a terminal you might only see a blinking cursor
If you type pwd, this will give you your current working directory’s absolute path
Here my current terminal output
pwd
/home/kursayurt
Now I know that I am on my home directory. I want to know which files or directories inside this directory. Simply typing ls is gives you that ones
ls
Blog
Desktop
Documents
Downloads
hello.cpp
Pictures
Project
Public
Templates
TUM
Videos
yd
As you see here is a hello.cpp file and some other directories are around here
Let’s go to my Desktop directory using cd command
cd Desktop
pwd
/home/kursatyurt/Desktop
Now as you see I have changed the current directory to my Desktop
ls
Ch8Sub.pdf worksheet2.pdf
cfdlab-lecture-notes.pdf
ws-navier-stokes.pdf
There is pdf files around. If I want to open one of them I can simply open them using xdg-open command which is open any type of file using default software defined by the system
xdg-open woorksheet2.pdf
To go back we can type
cd ..
pwd
/home/kursatyurt
This take us one directory back.
Now if I want to copy a file from my Desktop to Home directory, I can follow this thing.
cp ./Desktop/worksheet2.pdf .
Here cp command takes two arguments first one is the source and the second one is the destination
./ denotes from current directory by this way we can espace from writing absolute path. Also in the second argument . means here.
If we want to move a folder or file we use mv command which is similar to cp, one important thing about copy is you cannot copy a folder using cp command alone you need to give recursive flag -r
cp -r /source/directory /destination/directory
By this way one can copy a folder.
In order to create a new directory, we are using mkdir command
mkdir directoryname
This creates a new directory under our current directory as like any other linux command we can do operation other than our current directory giving absolute path
mkdir /absolute/path/to/directory
Now take a look at removing files/directories. An important thing about removing is that this operation is irreversible, no Trash Bin deleted files from command line goes.
Let’s first look into deleting files
rm FileName
Removing directories are requires a recursive operation
rm -r DirectoryName
One other important thing is of course when you are doing an operation or running a program you might want to cancel that process. For this purpose [Control]+c is used.