+-------------------------------------------------------------------------------+
| man |
| short for manual, it is a documentation usually found on a UNIX system. |
+-------------------------------------------------------------------------------+Format
man <commande>Example:
man lsRQ: RTFM means Read The Fucking Man
vi /etc/motd
Your messagecat file1 file2 > finalFileFormat
mkdir path/dirnameExamples:
mkdir myDir
mkdir /home/username/Desktop/myNewDirFormat
touch path/filenameExamples:
touch README
touch /home/username/Desktop/script.pyfile filenameFor multiple files, separate them with spaces.
file file1 /dir/file2echo "Hello " $(date '+%A %W %Y %X')su root -c "nano /etc/fstab"locate filenameTo be able to make a search, you have to build a database of your filesystem.
The norm is to execute updatedb in a cron: cron.daily at5 am. (see cron)
updatedbcalpwdwhoamidatelastFormat
ttyExample:
tty
/dev/ttys000Displays, by default, the number of lines, words, and bytes.
wc fileExample:
cat test.txt
This is a short line.
This is a second short line.
wc test.txt
2 11 51 test.txtFormat
which programExample:
which passwd
/usr/bin/passwdless myFile.txtchkconfig | lesschkconfig | grep sshd
#Search for sshd from listed services by chkconfigtar -zcvf file.tar.gz files /dirtar -cvf file.tar files /dirtar -xvf file.tartar -xvf file.tar -C /dirtar -tvf file.tarThe second line is the result of ls.
gunzip file.tar.gz
file.tarBy pressing the up arrow in the command line we'll see the last command we ran. Keep pressing up and we’ll see more commands; we can go back days, months, or even years.
This is called the history, and it’s very convenient. If we made a mistake typing a long command, simply press up and fix the problem. If we want to re-connect to an SSH server we used the other day, simply press up until we see the relevant command.
It’s useful, but there’s also a potential security problem here, particularly if we accidentally typed a password in plain text at some point. How could we clear the history?
Here’s how to do it.
If we want to remove the entirety of the history, we have to type this command:
rm ~/.bash_history.Alternatively, we could open the file and delete any lines we want to.
The history can be broke down into two parts. There’s the current sessions’ history, and the long-term history.
Our first command deals with the current session:history -c.The history command is built into Bash itself, and the -c modifier tells the program to clear that history.
This command will prevent anything in the current session from being written to the long-term history, but does not clear out that long-term history.
gzip file.txtgunzip file.txt.gzAlso shows ratio, uncompressed name.
Add -v for more infos.
gzip -l file.ext.gzzip file.zip fileszip -r file.zip /dir
You have to separate them with spaces.
zip -r files.zip file1 file2 /dirunzip file.zipcp fileName newFileNamecp fileName myDir/cp fileName myDir/newFileNamecp -R myDir myNewDircp *.jpg myDir/duFormat
du filenameExample:
du Desktop/Test/Grid.java
16 Desktop/Test/Grid.javaUse unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte.
Format
du -h filenameExample:
du -h Desktop/Test/Grid.java
8,0K Desktop/Test/Grid.javaFormat
du -sh myDir/Example:
du -sh Desktop/Test
22M Desktop/TestBe careful Without -name, the command will return that the file doesn't exist.
find / -name filename
#The file will be searched everywhere → '/'.find -name filenamefind / -mtime nfind / -mtime +nfind / -mtime -nlsTotal sum for all the file sizes is output on a line before the long listing.
ls -lThose whose names begin with a dot (.)
ls -aTo get reverse lexicographical order or the oldest entries first (or largest files last, if combined with sort by size).
ls -rls -RMost recently modified first before sorting the operands by lexicographical order.
ls -tls -lartThis option is equivalent to defining CLICOLOR in the environment.
ls -GSee man ls for more options
RQ: The rm utility removes symbolic links, not the files referenced by the links.
rm filerm -i filerm file1 file2Works also with -r
rm -R myDirrmdir myDirrm -f itemrm -rf {dir1,dir2}mv fileName newFileNamemv "myDir" "myNewDir"mv fileName myDir/newFileNameshutdown -h nowor
haltshutdown -r nowor
rebootuseradd usernamepasswd passworduserdel usernameYou have to be root
Format
service <daemon> startExample:
service sshd start
service sshd restartFormat
service <daemon> statusExample:
service sshd status
openssh-daemon (pid 2362) en cours d'exécution…Format
service <daemon> stopExample:
service sshd stop