Skip to content

Basics commands

CiamalaKombeGreg edited this page Oct 5, 2023 · 24 revisions

Basic commands of linux shell


man

The command man display a small manual with a explanation of how to use a command. You can write it man <command>. It is really useful as it give you all prefix that you can use with the command.

man ls
man mv

cd

The command cd allow you to navigate between directories. You can change from the current directory to another one by typing the name of the directory you want to go in cd <directory>, with the directory path cd /<directory>/<directory>/<directory>.

#I'm in system and I want to go in the directory documents

cd /home/system/documents
cd documents

There is also the possibility of using cd to step back in the parents directory by using cd alone which send you back to the root directory or cd .. and cd ../ who make you return to the parent directory of the current one.

#I'm in documents and doing cd while send me back to system

cd /home/system/documents
cd ..

pwd

This command give your current location. You can just type pwd.

mkdir

It create a simple directory if it doesn't exist. You can write it mkdir <directory>.

mkdir test1

touch

It can help create a simple file if it doesn't exit, but it principally update the access and modification time of a existing file to the current one. You can type it touch <file>.

touch test

cat

The command cat show the output of a file if it exist. You can use it by typing cat <file>.

cat test

mv

Could be use for different result, you can use it to move a file or directory (mv <source> <destination>) but it is also possible to rename them by putting the exact same location as a destination, in short typing mv <source> <new name>.

# to rename it test2
mv test test2

# to move to the parent directory
mv test2 ../

rm

This command delete files from the emplacement. You can delete them with rm <file>.

rm test2

grep

The command grep research a pattern of letters and word present in a file. For example, by typing grep galaxie test2 you would be able to find any iteration of the word "galaxie" in the file "test2". You can type it grep <pattern> <file>.

#There is a text written in the file test3 with two times the word "apple"

touch test3 # > "I like to eat apple with my families during free times, a fruit like a apple is good for health."
grep apple test3

chmod

This command allow you to change the permission of every users for each file.

User type

  • u : owner
  • g : group
  • o : others

Permissions

  • r : allow you to read
  • w : allow you to write
  • x : allow you to execute

These are prefix you can use to give specific instructions on how the file may interact with users. The general writing is chmod <user + permissions> <file>.

chmod u+r test3 # Allow the owner to read the file test3

chmod go+w test3 # Allow the member of a group and the others users to write in test3

chmod g-x, u+rw test3 #Disable the execute option for a group but make it possible for the owner to read and write in test3

chmod u=rwx, g=rw, o= test3 #Give every permissions for the owner, the permissions to read and write for a group and disable everything for others

ifconfig

Display and configure all network interfaces. You can type it as ifconfig.

chown

This command grant the ownership to another user. You can type it chown <new owner> <file>.

chown user1 test3

traceroute

This command print the route taken by packets to a network host. You can type it traceroute <ip>.

#This line give you the route to the dns server provided by google.

traceroute 8.8.8.8

ls

The command ls show a list of contents in the directory. It a numerous option that can allow you to display particular informations. The general writing is ls, you can also try ls -l, ls -i, ls -a, ...

echo

This command returns the outputs of the arguments that are given to him, it's possible to write in a file with that command by using indicators like >. The general command is echo <argument>.

#I'm writing the message "Hello" in the file test3
echo hello > test3

rmdir

In the same plage as rm, it allow you to delete a directory. You can write it as rmdir <directory>.

mkdir directTest
rmdir directTest

tail

The command tail display the last lines of a file. With the option -n, you can display a determined number of lines, use tail <option> <file> for example.

#Display the two last lines of the file
tail -n 2 test3

cp

This command copy a file, you can directly copy it in a directory by specifying it at the end. You can try cp <file> <destination directory>.

mkdir copyDirectory
cp test3 copyDirectory

head

It is the opposite of tail which this time display the first lines of a file, you can type it as head <option> <file>.

#Show the three first lines of the file.
head -n 2 test3

Clone this wiki locally