run commands in a terminal
To run commands in a console or terminal, you would start with the command abbreviation, followed by possible given options or parameters. For example, to run the command ls
in a terminal, you would type ls
and press enter. The command ls
lists all files and directories in the current directory.
[command] [-options] [parameters]
navigate the command line
Or, to navigate to a specific directory you would type cd
followed by the directory name, for example cd Documents
. To run the command cd
without any parameters, you would type cd
and press enter. This would navigate you to your home directory.
cd folder/
cd folder/subfolder/file.txt
log into text mode consoles
to log into linux text mode remote consoles you would type ssh
followed by the username and the ip address of the remote machine. For example, to log into a remote machine with the ip address 192.168.0.1
and the username root
, you would type ssh root@192.168.0.1
and press enter.
ssh user@domain
zipping files and directories
To zip files and directories you would use the command zip
. For example, to zip the directory hello
and all its contents, you would type zip -r hello.zip hello
and press enter. To unzip the file hello.zip
, you would type unzip hello.zip
and press enter.
zip -r hello.zip hello
unzip hello.zip
create, delete, copy, and move files and directories
To create a file, you would use the command touch
. For example, to create a file named hello.txt
, you would type touch hello.txt
and press enter. To delete a file, you would use the command rm
. To copy a file, the command cp
, and to move a file, you would use the command mv
. Which also works for directories and can me used to rename files and directories.
touch hello.txt
cp hello.txt hello2.txt
mv hello2.txt hello3.txt
rm hello3.txt
search and compare text files
You can search files via find
and grep
. For example, to search for the string hello
in all files in the current directory, you would type grep -r "hello" .
and press enter. To search for the string hello
in all files in the current directory and all subdirectories, you would type grep -r "hello" *
and press enter. To search for the file hello.txt
in the current directory, you would type find . -name "hello.txt"
and press enter.
find . -name *.txt
grep -r "hello" .
and also compare them with diff
. For example, to compare the files hello.txt
and world.txt
, you would type diff hello.txt world.txt
and press enter.
diff file1.txt file2.txt
read, and use system documentation (man)
To read the manual for a linux command you would type man
followed by the command abbreviation. For example, to read the manual for the command ls
, you would type man ls
and press enter.
man diff