DRAFT
The Linux command line is very popular because you have more commands and options at your fingertips than with your desktop applications and you can script repetitive tasks, create aliases and write shell functions. You can also use the bash command line in the Windows Subsystem for Linux.
If you know what you want to do but can't remember the command you need, use apropos. Typing apropos followed by whatever you're interested in, like "printing" or "remote connection", lists all the commands associated with that topic. For example, “apropos printing” will list all the commands about printing. Other resources:
6 Linux Terminal Mistakes Beginners Make
10 Basic Linux Commands for Beginners
37 Important Linux Commands You Should Know
Synthasix:
Linux is case sensitive. We keep capital letters for variables.
No accent or space is used.
Under Linux all is file and there is no extension
We do not see the partitions, there is only one file system
It is possible to group the parameters ls -lisa -color=tty (equivalent to ls -l -i -s -a -color=tty)
Joker : * and ? (one character)
&& allows to chain commands
Navigation - Commands:
- Cd ~ ⇒ go to my home folder
- Cd toto ⇒ relative addressing
- Cd /home/henchoz-d/toto ⇒ absolute addressing
- Cd . ⇒ Where I am
- Cd .. ⇒ back to where I came from (parent directory on the top floor) don't forget the space
- Cd / ⇒ return root
Example: Three ways to go from /usr/local/doc to /usr/X11R6/doc.
1.
- cd ..
- cd ..
- cd X11R6
- cd doc
2.
- cd ../../X11R6/doc
3.
- cd /usr/X11R6/doc
Home folder = /root
~ (tilde) indicates home folder
My folder = /home/henchoz-d
Files starting with "." are hidden
Navigation - File Structure:
"bin" contains commands necessary for system startup.
"sbin" contains commands needed for system startup, reserved for the system administrator or superuser
"etc" contains all configurations of all applications, general configuration files, commands to be executed at system startup, system startup mode
"proc" is virtual, created in memory
"tmp" temporary
"usr" for applications Multi-purpose directory, the main ones being :
/usr/bin Commands usable by all users, and not necessary during system startup.
/usr/sbin Commands reserved for the super-user, and not necessary during system startup.
/usr/man Contains man pages
/usr/doc Contains many documentation and information sources.
/usr/X11R6 Contains all files related to the X-Window graphics layer
/usr/local Place where files specific to the installed system are stored.
"home" personal folders of all users
"lib" and "lib64" (equivalent to dll?)
"media" and "mnt" (mount) are places where removable media and network shares are attached
"srv" server-specific information and programs
"sys" system
"var Log files. Contains data updated by various programs during the operation of the system.
/var/lock Blocking files, for example to prevent two simultaneous uses of the modem.
/var/spool Directories used for organizing the work of printers, e-mail, etc.
/var/log Contains log files from various points on the system.
"dev This directory contains all the special files used to access the hardware, whether it is the keyboard, the hard disk, the sound card...
Important files
/etc/passwd ⇒ The users file
/etc/group ⇒ The group file
Structure : Name:Password:User number:Group number:Special field: Home directory:Startup program
/etc/inittab ⇒ Specifies the system boot mode and associated actions.
/etc/fstab ⇒ Lists the partitions used by the system and how it uses them.
XF86Config ⇒ Can be located in different places (but often under /etc/X11) depending on the distribution used. Contains the configuration of the graphics layer
vmlinuz... ⇒ Is usually located either under the root (/) or under /boot. It is the system itself!
Prompt :
henchoz-d@vador:/$ username@machinename:currentfolder
# ⇒ indicates that you are root
$ ⇒ indicates that you are user
Redirection
Send the display to a folder rpm -qa > all_packages.txt
Redirections can be done in the other direction. Take what is in a file
mail untel at tel.adresse < message.txt
Commands
[] optional
{} choose one of these options
Commands under bash (there are 400 basic bash or sh commands):
Type a letter then TAB TAB to see the commands
Cat (catalog) ⇒ displays the contents of the file
Chmod - sets file permissions (see paragraph at the bottom of the document)
Clear ⇒ clears the screen
Cmp ⇒ allows to compare files
DD instead of cp ⇒ allows a bit by bit copy (including the size of the partition so expand the partition with expandfs)
Diff - compares two files and shows their differences?
Df -h ⇒ allows to know the total disk space occupied and remaining on the partitions of your system
Dmesg ⇒ kernel log
Du ⇒ show the disk space used by the files in a directory
echo $PATH ⇒ to see the environment variables
export PATH="$PATH:/foldername" ⇒ to add a variable
find ⇒ find files
ex : find / -name core finds from the root the files named core
ex : find / -mtime -2 finds files modified within two days
find /volume1/Personnel -maxdepth 15 | grep -P '\/
\/{143,}^\/' (finds all filenames longer than 143 char)
Grep - searches files for matches. grep 'string to search' file ⇒ searches the file if it contains the string to search
ex : grep 'string to search' foldera/* folderb/* searches in the files belonging to foldera and folderb if they contain the string to search (-i to ignore the box)
Groups ⇒ to display the groups you belong to
Gzip ⇒ to compress files
ip addr - find your ip address
Ifconfig ⇒ equivalent to ipconfig
Join ⇒ mix two files on the screen
Kill ⇒ interacts with procedures
Ex : kill -1 process number allows to reset a process
Ex : kill -15 process number allows to stop a process gently
Ex : kill -9 processnumber allows to force a process to stop
Less ⇒ allows to display a file on the screen (like more but better)
Ln ⇒ creation of a link
Ex : ln tata tatacopie creates a "hard" link. Both files point to the same place, deleting one does not affect the other
Ex : ln -s tata tatacopie creates a "symbolic" link. Both files point to the same place, deleting the original one makes it impossible to open the symbolic link. A symbolic link is indicated by -> by doing ls-l
Ls ⇒ list sort (equivalent to MS-DOS dir) -a with hidden files; -l with details; -R with subdirectories; -color=tty with colors (remember to do an apt-get install tree)
Ls -al ⇒ lists the files, including hidden ones, with details (allows to see the permissions)
Ls -Al ⇒ lists the files, without hidden ones, with details (allows to see the permissions)
Ls -p ⇒ adds the / indicator to directories
Ls -g ⇒ groups directories before files
Ls -al |less ⇒ pause screen (space bar to continue)
Ls -al | less grep texmf ⇒ lists only what contains texmf
Man command ⇒ manual (equivalent to /h) q to quit, preferable to help
Command -help ⇒ to get help on a command
More ⇒ to display a file on the screen
Ps a ⇒ to get a list of all processes
Ps -ef | grep processname ⇒ to know the status of a given process
Pwd ⇒ displays the tree of the current directory
Reboot ⇒ restarts
Service --status-all ⇒ list the services and display their status
Shutdown -h now ⇒ stops
Smbclient //machine/directory -U administrator -l 192.168.1.1 ⇒ access the share
Startx ⇒ start a graphical session on a remote server
Stat ⇒ allows to have detailed information about a file (creation, modification)
Su (sudo) ⇒ become super user - allows a user to run a program as the root user
tar ⇒ to archive files
Traceroute ⇒ equivalent of MAS-DOS tracert
Uname -a ⇒ system info
Userdel ⇒ delete a user account
WhoAmI
Who ⇒ displays the current users
Some commands (especially administration commands) are not available to users.
Pipes:
|(pipe) ⇒ passes the result of the previous command
This mechanism allows to chain the execution of several commands
Example, the following two commands:
- ls -alR / > all_files (lists all files on the system and sends the result to the "all files" file)
- grep doc all_files (searches for "doc" in the "all files" file)
becomes
- ls -alR / | grep doc
======
The chmod command sets file attributes, much like the Windows attrib command does. On Linux you can set permissions for reading files, writing to files, and executing files, with a different set of attributes for the file owner, the user group the file belongs to, and everyone else. These attributes can also be applied to directories.
0: No permission
1: Execute permission
2: Write permission
3: Write and execute permissions
4: Read permission
5: Read and execute permissions
6: Read and write permissions
7: Read, write and execute permissions
The file "howtogeek.txt" has full permissions set for everyone. We'll change that to full permissions for the owner (7), read and write (6) for the group, and read (4) for all others.
chmod 764 howtogeek.txt
======
Here are some training videos that might interest you
Linux Commands
Linux Features