-
LINUX > informations sur le système
- Duplicate files
- Problematic filenames
- Temporary files
- Bad symlinks
- Empty directories
- Nonstripped binariespython2 /usr/bin/fslint-gui
- ~/.profile has the stuff NOT specifically related to bash, such as environment variables (PATH and friends). Anything that should be available to graphical applications OR to sh (or bash invoked as sh) MUST be in ~/.profile
- ~/.bash_profileshould just load .profile and .bashrc (in that order)
- ~/.bashrc has anything you’d want at an interactive command line: command prompt, EDITOR variable, bash aliases
- Ensure that ~/.bash_login does not exist.
- Put your aliases in .aliases and modify:
- Put all the files you want to save in a given directory, e.g. /tmp/mycd.
- Create an iso image:
mkisofs -o cd.iso -J -R /tmp/mycd ls -l cd.iso
Check that the resulting file cd.iso file is not too large to fit on the CD; if it less than 650Mb, this should be ok.
- Record on the cd (you must be root).You must know which is the device is associated to the CD writer drive.
cdrecord -scanbus
To determine the x,y,z scsi coordinates of your cd writer. If it does not appear listed, it may be because the ide-scsi parameter was no passed to the Linux kernel (See the HOWTO about CD Writing).
To record, do:
cdrecord dev=x,y,z -multi speed=0 -data cd.iso
- Click the left button and drag the cursor over the text to be copied.
- Click on the middle button to paste.
DISTRIBUTION, KERNEL
lsb_release -a
Version du noyau :
uname -a
Nombre de CPU/cœurs :
lscpu
RAM installée et utilisée :
free -h
Check le filesystem :
lsblk df -h
Real-time overview of usage:
glances
Niveau de la batterie :
acpi -i
Find files or directories
To locate the file named ‘filename’ in all the subdirectories of the current directory:
find -iname 'filename'
You can use a pattern in place of ‘filename’, e.g. to return the list of all .doc files in the current directory and its subdirectories:
find -iname '*.doc'
The depth of subdirectories visite can be limited:
find -maxdepth 2 -name '*.doc'
With -o your can do an ‘or’. For example, to search for for files with extension nii or img:
find -name '*.nii' -o -name '*.img'
With !, you can negate a search:
find ! -name '*.nii'
You can specify a time-range:
find -mtime 0 # find the files created or modified in the last 24hours find -mtime +30 -mtime -60 # find files modified in the last 30-60 days find -newermt 20171101 ! -newermt 20171201 -name '*.pdf' -ls # find pdf files modified between two dates
You can specify that you only search for, e.g., directories, using the -type argument:
find -type d # list all subdirectorectries find -type d -mtime -10 # find the directories created or modified in the last 10 days:
You can find and delete all empty directories:
find . -type d -empty -print find . -type d -empty -delete
You can filter on permissions
find -perm -o+x -ls -type f # list all file with the execute flag set on 'others'
You can also execute a command on each file:
find -name '*~' -exec rm '{}' '+' # delete all files '*~' find -name '*.py' -exec mv -t path '{}' '+' # move all py files to path find -name '*.txt' -print0 | xargs -0 grep -l Alice # show files
Note that xargs can be parallelized with the -P option:
find -name '*.nii' -o '*.img' -print0 | xargs -0 -P 10 gzip # gzip all image files
Consult info find and info xargs for more information.
To accelerate file search, you can generate a database of all filenames on you filesystem:
updatedb
And then use the command
locate PATTERN
Note that the locate will return all files where PATTERN matches any substring in the full pathname (including directories).
Search files by content
grep PATTERN file
where PATTERN is a regular expression (See man grep).
To search files recursively in subdirectories, you can combine find and grep:
find -type f -name "*.tex" -print0 | xargs -0 grep -n PATTERN
But this is complex! An interesting alternative is to use ack (https://beyondgrep.com/). By default, it does a recursive search and it can focus on certain file types.
ack --python -w TOKEN # search only python file matching on word 'TOKEN'
To install ack under ubundu:
sudo apt install ack-grep
Another search tool, which I have not used but is said to be faster than ack is ag http://conqueringthecommandline.com/book/ack_ag:
sudo apt install silversearcher-ag
Tools like grep and ack are useful to search within text files but pretty useless for binary files. If you want to search within .pdf or .doc files, you first need to extract the textual content and then index it. Then, you will be able to search files by their content. To this end, you can install and use a tool like recoll (see http://www.lesbonscomptes.com/recoll/). One issue though it that the index can quickly grow very large.
Synchronize two directories
To copy the content of dir1 into dir2 without the copying the files that already exist and are the same, use rsync:
rsync -a dir1/ dir2
If you want to copy the newest files and delete the ones (make dir2 a mirror copy of dir1:)
rsync -a --delete dir1/ dir2
rsync compares the files’ contents which can be quite slow. You can considerably speed up the transfer if you accept that files with the same file sizes are considered unchanged:
rsync -r --size-only dir1/ dir2
To synchronize two directories (in both directions), I use the program unison, which keeps two directories synchronized, transfering only new or modified files, in both directions:
unison localdir ssh://remotehost/remotedir
Check the amount of disk space occupied by files or directories
To list the files in the current directory sorted by size:
ls -Sl
To display the size occupied by a directory:
du -h dirname
To find the largest sub-directories:
du -k | sort -rn
The following tools are quite handy to detect large files and clean one’s hardrive
ncdu # interactive du with ncurses interface baobab # gui du
Find duplicate files
The command fdupes finds duplicate files and list them.
fdupes -r
A more powerful tool, fslint-gui, can detect :
Add a directory to the PATH
Most commands that you can execute from the command line are compiled programs or scripts. The shell (the program with which you are interacting most of the time with when typing commands in the terminal) searches for these programs in a list of directories. This list is stored in an environment variable called PATH. You can display its content:
echo $PATH
Note that when several directories contain a program with the same name, the first directory listed in the PATH variable has priority.
It is possible to find out which directory contains a given command by typing:
which command
Beware that an alias may shadow the command. It is therefore more informative to type
type -all command
To add a new directory newdir to the list in PATH, type:
export PATH="newdir":"$PATH"
Add this line to the file $HOME/.profile (on a Debian-based linux like Ubuntu) and source it:
. .profile
The following three functions, to be added to your ~/.profile or ~/.bashrc, allow you to edit the PATH on the command line by removing, adding or substituting strings within the PATH variable.
path_unset(){ # remove a directory from PATH pattern=$1 PATH=$(echo $PATH | sed -e "s/[^:]*${pattern}[^:]*//") } path_sub(){ # substitute a substring in PATH from=$1 to=$2 PATH=$(echo $PATH | sed -e "s/${from}/${to}/") } pathmunge () { # add a directory to PATH if it not already there if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then if [ "$2" = "after" ] ; then PATH=$PATH:$1 else PATH=$1:$PATH fi fi }
Finally, there is remarkable set of functions that allow you to bookmark and jump directly to subfolders: see dirb at https://github.com/icyfork/dirb.
Note: In case your SHELL is tsch or csh instead of bash, type:
set path = (newdir $path) rehash
Place these lines in the file ~/.cshrc , to have the correct PATH the next time you open a shell.
Startup files
.bashrc:
if [ -f ~/.aliases ]; then . ~/.aliases fi
.zshrc:
source $HOME/.aliases
(from https://superuser.com/questions/789448/choosing-between-bashrc-pandrofile-bash-profile-etc)
List the programs currently running on the system
To list all the processes currently running:
ps -ef
(you may omit the ‘a’ option if you want to list only the processes owned by you, and -l if you want less information)
The most important columns are ‘time’ and ‘RSS’ which show the time used by process since it started and the amount of real memory it takes.
If you want to list just some programs, for example `matlab``, type
pgrep -a matlab
Sometimes, it can useful to find the process that own an open file:
lsof
(See http://www.thegeekstuff.com/2012/08/lsof-command-examples/)
Kill a program that is no longer responsive
It may happen that a program monopolizes most of the CPU, but does not longer respond to input. Such a program is crashed and should be "killed"".
For applications running in a terminal, first try to press Ctrl-C.
If this does not work, or if the application is running in its own window but refusing to close, open a terminal and type:
pkill program_name
You can also use the command ps -ef to locate the application and note down the "process identification number" in the ‘PID’ column. Then, type:
kill PID
(in place of PID, use the number associated to the process listed in ‘ps’ output). Check if the program was destroyed with the ps command; if not:
kill -9 PID
If the whole graphics system no longer responds, you can try to open a text mode terminal with Ctrl-Alt-F1 or Ctrl-Alt-F2, log in and kill the programs that causes problem. Sometimes, the only solution is to kill Xorg, the display server). display).
It the keyboard does not repond anymore, before switching off the computer, you can try to connect from another computer on the same network and kill the applications or do a proper shutdown (typing ‘halt’ on the command line).
Use git to keep an history of your projects and collaborate
Another approach to synchronise dirs is to use git repositories.
Learn about git by reading https://git-scm.com/book/en/v2
See also git-annex
Create a copy of a local git repository on github.com
git push --mirror git@github.com:username/project.git
Disable the Touchpad while typing
killall syndaemon syndaemon -i 1 -KRd
The system is not responding
Try Ctrl-Alt-F1 to open a terminal. From there, you might be able to do:
sudo shutdown now
Alternatively, press Alt+PrintScr, and, keeping this key pressed, type, slowly, reisub. This mysterious sequence is explained at https://linuxconfig.org/how-to-enable-all-sysrq-functions-on-linux#h6-the-sysrq-magic-key
change the brightness of the display
sudo brightlight -r # read sudo brightlight -i 10 # increase sudo brightlight -d 10 # decrease
or
xbacklight -set 50
or
xrandr --output eDP1 --brightness 0.5
Lock the screen under X11
Assuming that xscreensaver is running in the background.
xscreensaver-command -lock
or:
i3lock -d 30 # if you use i3wm
Suspend to RAM
sudo pm-suspend
Reboot
reboot
Shutdown
poweroff
Manipulating Images
Make sure to have ImageMagick installed (e.g. sudo apt install imagemagick on a Debian-based system)
To display an image (gif, .jpg, .png, .tiff, eps, …)use:
display file.gif eog image.png
To convert from one format to another:
convert file.jpg file.png
To resize an image:
convert img.png -resize 66% img_small.png
To juxtapose several images:
montage -tile 4x4 *.png -geometry 1024x768 output.png
To superimpose images:
composite img1.png img2.png result.png
For more complex manipulations of bitmap image, I use The Gimp:
gimp file.jpg
To manipulate photographs, I like (Lightzone)[http://lightzoneproject.org/]
Diaporama:
feh
Creating graphics
l To edit vector graphics files, e.g. .svg:
inkscape
To draw graphs:
dot
To plot data, I use R or IPython:
import matplotlib.pyplot as plt import numpy as np
Take a screenshot
To take a snapshot, that is, copy a portion of the screen into an image file, you can use ImageMagick’s command import:
import file.png
You will then be able to select a rectangle on the screen with the mouse, which will be copied in file.png.
Other screenshot programs include gnome-screenshot, ksnapshot, scrot, maim… See https://wiki.archlinux.org/index.php/Screen_capture for a list.
Make a screencast
Voir http://www.linuxlinks.com/article/20090720142023520/Screencasting.html
Under i3, see https://github.com/synaptiko/.files/blob/4a6a549dfe0c22d19f38e32129b5c05de2bb6d34/i3/record-screen.sh
Links
To create a symbolic link (somewhat similar to a ‘shortcut’ in Windows):
ln -s filename newname
If you delete or move the file, the symbolic links will be ‘dangling’.
To find and remove dangling links in a directory:
symlinks -rd directory
Convert a directory into a single file
Say you want to all the files in a directory in an email attachment. You can put a whole directory into a file ``file.tar'’ with the command:
tar cf file.tar directory
Before sending it, it a good idea to compress ``file.tar'’, as described in the next section.
Compress / uncompress files
To compressing a single file:
gzip file
To decompress it:
gunzip file.gz
Better compression can be achieved with xz, which has the same syntax as gz:
xz file # compress unxz file.xz # uncompress
To compress a full directory:
tar czf aga.tar.gz directory # compressing tar tzf aga.tar.gz # listing tar xf aga.tar directory # uncompressing
Other popular formats are .zip and rar:
zip -r archivename directory unzip -l archivename.zip unzip archivename.zip rar file unrar file.rar
Convert text files from DOS, Windows, Mac…
Texts files under unix, mac, dos and windows use differents codes for end-of-lines and accentuated characters.
To detect the character encoding, one can use uchardet
uchardet file.txt
or
file -bi file.txt
Once you have determined the character encoding, you can use iconv or recodeto convert the file. `iconv`` is often installed by default.
iconv -f ISO-8859-1 -t UTF-8 file.txt > file.utf-8.txt iconv -f WINDOWS-1252 -t UTF-8 file.txt > file.utf-8.txt
The recode program has a nice info documentation. By default, it does the transformation in place:
To convert file.txt coming from a Macintosh:
recode mac..latin1 file.txt
To convert from DOS codepage 850 to unix latin1:
recode 850..latin1 file.txt
To just remove \^ M:
recode l1/crlf..l1 file.txt
To convert from Windows codepage 1250 to unix latin 1 (iso-8859-1):
recode ms-ee..l1 file.txt
Delete all lines matching a pattern in many files
find -name FILENAME_GLOB -type f | xargs sed -i -e '/PATTERN/d'
Substitute strings in many files
find -name FILENAME_GLOB -type f | xargs perl -pi.bak -e 's/OLDSTING/NEWSTRING/g' # attention: to match words only, use s/\bOLDSTRING\b/NEWSTRING/g
Compute word frequencies in a text file
To compute the number of occurences of words in a file, say alice.txt:
tr -cs A-Za-z\' '\n' alice.txt | tr A-Z a-z | sort | uniq -c | sort -k1,1nr -k2 | head -10 1637 the 1083 ' 872 and 730 to 631 a 540 she 528 it 513 of 460 said 410 i
Run a command on multiple files
It is sometime useful to run a command on many files. The shell bash provides ‘for’ loops:
for f in *.eps; do convert $f ${f%.eps}.jpg; done # convert .eps files in the current directory into .jpg
Note that this is only valid if you are interacting with the shell ‘Bash’. If you use another shell then you must type ‘bash’ first.
Another possibility is to use the find command with xargs
find -name *.eps -print0 | xargs -0 commands find -name *.eps -exec command '{}' ';'
Count the number of files in a directory
To know how many files with extension .img are in the current directory:
ls *.img | wc -l
If you want to include all subdirectories:
find -type f -name '*.img' | wc -l
List files and subdirectories
ls ls -1 # in one column ls -l # with detailed format ls -d # only directories ls -l --sort=time | head # most recent files only
Create subdirectories
mkdir -p subdirname
Copy, rename, move or delete files
To copy a file in the same directory, giving it name2:
cp file1 file2
To copy a file from the current directory to the existing directory dir:
cp file1 dir
To rename a file:
mv file1 file2
To move a file to the existing directory dir:
mv file1 dir
To delete a file:
rm file
To avoid being asked for confirmation:
rm -f file
Copy, move or delete directories
To create a new directory:
mkdir newdir
To copy the directory ‘dir’ in the destination directory ‘destdir’:
cp -a dir destdir
(Note: the ‘-a’ option does a recursive copy - that is includes the subdirectories - and preserves the attributes of files)
To move the whole directory ‘dir’ inside the existing ‘destdir’:
mv dir1 destdir
To rename directory ‘dir’ as ‘dir2′:
mv dir dir2
To delete the directory ‘dir’ and all its content:
rm -rf dir
Renaming files, replacing their name by their creation date
#! /bin/bash for fullfile in "$@"; do filename=$(basename "$fullfile") extension="${filename##*.}" filename="${filename%.*}" mv -n "$fullfile" "$(date -r "$fullfile" +"%Y%m%d_%H%M%S").${extension}"; done
Check or modify the rights of access to a file or a directory
When you use ls -l to list the files in a directory, the first string of characters, made of ‘x’, ‘r’ ‘w’, ‘-’… specifies the access rights (Consult Understanding file permissions on Unix: a brief tutorial)
To allow everybody to read all the files in the current directory:
chmod a+r *
If, when using ls -l, there is a + sign is trailing the rights, it means that ACL (Access Control List), is set on the files or directories. The chmod command will not work: you must then use the getfacl and setfacl commands to list or modify the access/write rigths
Link files
To avoid copying a file in several places on the same disk, it is a better idea to use a link:
ln existingname newname
Thus the same file can have several names (and be in several directories at the same time).
Who am I?
As far a the computer is concerned, the identity of the current user (that is its login), can be printed with:
whoami
Note that your login name, home directory, and shell are saved in the environment variables LOGNAME, HOME and shell:
echo $LOGNAME $HOME $SHELL
Change your identity
To temporally become newuser:
su - newuser
Of course, you will be prompted for newuser’s password.
If you want to become root:
sudo -i
When you are done, type:
exit
Each login is associated to a UserID (UID), an integer, an to list of GroupIDs (GUID). You can list the information linked to the current login:
id
It is sometimes necessary to change your UID number, for example when you swap an external hardrive with a unix filesystem. Here is how to do it:
usermod -u <NEWUID> <LOGIN> groupmod -g <NEWGID> <GROUP> find / -user <OLDUID> -exec chown -h <NEWUID> {} \; find / -group <OLDGID> -exec chgrp -h <NEWGID> {} \; usermod -g <NEWGID> <LOGIN>
Change group
Check which groups you belong to using id, then use
newgrp group
From now, the files and directories you create will belong to group group
To modify the group of already existing files in directory dir:
chgrp -R group dir
Which computer/system am I currently working on?
To display the network node name (also called the ``hostname'’):
uname -a
The following also works:
hostname
Check who is logged on the computer
To see who is currently logged on the system, use
who
or
w
If you are superuser, you can see a journal of the logins with the command:
last
Check the performance of your computer
You can monitor your system with glances:
glances -t 5
or with htop:
htop -d 50 --sort-key PERCENT_CPU htop -d 50 --sort-key M_RESIDENT
There are more specialized tools that focus on subsystems. For example, you can monitor the global activity of the CPUs with:
mpstat 5
To monitor the memory usage in real-time:
vmstat -S M 10
If any of the indicators si (swap in) or so (swap out) are high, your computer lacks memory and is using the swap (memory on disk).
You can check the file input/ouput volume and speed on the local drives:
iostat -x 2 5 iostat -h -d 10
Check the speed of your ethernet connection. Three tools are available:
mii-tool ethtool iperf
Or the general network performance:
netstat -i 10
Large TX-ERR or RX-ERR indicate a problem.
To check the temperatures:
sudo apt install lm-sensors hddtemp sudo sensors-detect sensors
You can then to install psensor to continously monitor:
sudo apt install psensor
check power consumption
Two tools can be used to monitor power usage:
sudo powertop powerstat
If you have a nvidia card:
nvidia-smi
Connect to a remote computer
A secure method to connect to a remote computer:
ssh computername
or
ssh login@computer
Note that the remote computer must be running a ‘sshd’ server.
In the good old days, it was possible to connect with the commands:
rlogin computername telnet computername
Note that the login and password were sent in clear over the network, and that is why ssh is prefered nowadays.
Execute commands on a remote computer, without login
ssh login@computername command
Keeping a remote session alive
Once connected on the remote computer, execute:
tmux
When you want to leave, press Ctrl-b d. The terminal is detached but not closed.
Next time you connect to this remote computer, to continue your work, you can access the session:
tmux a
See https://danielmiessler.com/study/tmux/ for a primer on tmux.
Copy files to or from a remote computer
scp -r localdir remotelogin@remotecomputer:remotedir rsync -avh localdir/ remotelogin@remotecomputer:remotedir tar -cf - dir | ssh login@remotehost tar -xvf -
To synchronize bidirectionnaly:
unison
To ‘aspire’ web pages:
wget address curl address
If you need to use ftp, you can use the following clients
ncftp lftp
Setting up SSH
To avoid having to type your login password each time you use ssh or scp, you can setup SSH to use public and private keys to perform the authentification automagically.
First, you must generate keyfiles, once, on your local computer. To do so:
ssh-keygen
This generates, among other files, a public key stored in a file ~/.ssh/identity.pub). You now need to copy this key in the authorized_keys file inside the ~/.ssh directory of the remote computer you want to connect to.
ssh-copy-id remotecomputer
If you have let an empty passphrase, you can know use ssh or scp without entering your password. But so can do anyone who access your account on your local computer.
So you may prefer to use a passphrase. To avoid having to type it each time you log to the remote computer, copy the following lines in your ~/.bash_profile:
eval `ssh-agent` ssh-add < /dev/null
You will be prompted for the passphrase only once: when you login on the local computer (See the explanations about ssh-agent at http://mah.everybody.org/docs/ssh).
Display locally the interface of an XWindow program running on a remote computer
The X Window graphic system used by Linux allows to see on the local computer graphic windows generated by a program running on a remote computer.
On the local computer, type:
xhost +
On the remote computer, type:
export DISPLAY=localname:0 # if the shell is bash
or
setenv DISPLAY localname:0 # if the shell is a csh derivative
Replace localname by the name of local computer. If you do not know it, type the following on the local computer:
uname -n
Setting up X11 forwarding with ssh
To allow graphical applications ran on the server to display their windows on the local computer, when using ssh:
X11 forwarding needs to be enabled on both the client side and the server side.
On the client side, the -X (capital X) option to ssh enables X11 forwarding, and you can make this the default (for all connections or for a specific conection) with ForwardX11 yes in ~/.ssh/config.
On the server side, X11Forwarding yes must specified in /etc/ssh/sshd_config. Note that the default is no forwarding (some distributions turn it on in their default /etc/ssh/sshd_config), and that the user cannot override this setting.
The xauth program must be installed on the server side. If there are any X11 programs there, it’s very likely that xauth will be there. In the unlikely case xauth was installed in a nonstandard location, it can be called through ~/.ssh/rc (on the server!).
Note that you do not need to set any environment variables on the server. DISPLAY and XAUTHORITY will automatically be set to their proper values. If you run ssh and DISPLAY is not set, it means ssh is not forwarding the X11 connection.
To confirm that ssh is forwarding X11, check for a line containing Requesting X11 forwarding in the ssh -v -X output. Note that the server won’t reply either way, a security precaution of hiding details from potential attackers.
Modify the password
To change your password a local system:
passwd
To change your password on a network administrated with NIS (``yellowpages'’):
yppasswd
Change the login shell
To change your password on the local system:
passwd
To change your login shell, e.g. from /bin/csh to /bin/bash:
ypchsh
or
chsh -s /bin/bash
Split a large file on several floppies
First compress the file, with gzip or bzip2 (see section41). If it still does not fit on a single floppy (1.4Mb), you can use the command split:
split -b1m file
This create a series of x?? files which you can copy on separate floppies.
To reassemble the files:
cat x* >file
Rip sound files from an audio CD
On, the command line, you can use cdparanoia. For example, to rip an entire audio CD:
cdparanoia -B
To rip just one track:
cdparanoia -w track_number file.wav
Maybe an easier way to copy tracks from an audio cd it to open konqueror, and type ‘audiocd:/’ in the address bar. This will show you the content of the CD, which you can copy somewhere else. Copying from the mp3 or ogg folders will do the automatic translations for you.
Else, there are various programs with graphical interface which allow you to rip audio CD: grip and kaudiocreator, rhythmbox.
Create a data CD
Create an audio CD
To put on an audio CD all the *.wav files which are in the current directory:
cdrecord dev=x,y,z -pad speed=0 -audio *.wav
(x,y,z must be replaced by the numbers returned by cdrecord -scanbus)
Make backups
You can write backup scripts rsync but it has already been done many time. I recommend backintime
Connect to a bluetooth device
sudo service bluetooth start sudo service bluetooth status rfkill list rfkill unlock 0: bluetoothctl power on devices scan on pair XXXXXXX connect XXXXXX
Convert doc or odt documents to pdf
libreoffice --headless --convert-to pdf *.odt
List the hosts in a NIS domain
If you are connected on a local network administrated by NIS (``yellow pages'’), you can display the list of other computers on the network:
ypcat hosts
Mounting a Samba Share
Assuming you have a SAMBA server with IP 192.168.0.50
smbclient -L 192.168.0.50 sudo mount -t cifs //192.168.0.50/BACKUPS /mnt -o username=chrplr,file_mode=0777,dir_mode=0777
Which shell is running?
When you enter commands on the command line in a terminal, the text you type is interpreted by a program called the ‘shell’. There are different shells that speak different dialects. To determine the shell you are communicating with, type:
echo $SHELL
Note: this does not work well for subshells:
bash echo $SHELL csh echo $SHELL exit exit
Create a script to execute a series of commands
If you happen to often type the same series of commands, it is a good idea to create a script.
If it does not exist yet, create the directory \$HOME/bin.
Use a text editor to create a file ‘myscript’ in this directory, and type the series of commands.
The first line of the file should be:
#! /bin/bash
Save the file, then enter the command:
chmod +x ~/bin/myscript
You can now type ``myscript'’ on the command line to execture the series of commands.
To go further, you should learn how to use arguments to scripts. There are tutorials on shell script programming on the web.
Get help. Find manuals
Many commands have associated ``man pages'’. To read the man page associated, for example, to the command ‘cp’:
man cp
Some commands also have manuals in the form of ‘info files’:
info gawk
On many linux systems, there is additional documentation in the /usr/share/doc folder. The HOWTOs can be especially helpful.
Cut’n paste
Cutting & pasting under linux is not always straigtfoward. This is due to the fact that there are various systems of cut’n paste cohabitating.
To copy text, the following works with most applications:
Note that this is very convenient: there no need to explicitly ‘copy’ the text.
If you use the window manager ‘kde’, there is a useful applet called ‘klipper’ located on the panel. Klipper keeps copies of the most recent clipboard contents. If a cut’n paste operation does not work, you may open klipper, select the relevant line, and retry to paste. It usually works.
If it does not work, then you can try the Cut/Copy/Paste functions from the applications’ menus. Sometimes, it is necessary to save the region as a file in the first application, and insert this file in the second application.
Mount a partition of a usb drive
Insert the USB drive, use lsblk or dmesg to find partitions, then use pmount or udisksctl:
lsblk pmount /dev/sdb1 udisksctl mount -b /dev/sdb1
Setup an ethernet card to access the internet
You need to know IP, MASK, GATEWAY, DNS, HOSTNAME and DOMAIN:
ifconfig eth0 IP netmask MASK up route add -net default gw GATEWAY netmask 0.0.0.0 eth0 hostname HOSTNAME echo ``domain DOMAIN'' >/etc/resolv.conf echo "nameserver DNS" >>/etc/resolv.conf
Changing/Editing network connection
nmtui # text mode nmcli # text mode unity-control-center
Dynamic libraries
To run, some programs need to access functions in dynamic libraries. Dynamic libraries have the extension .so. They are located in /lib, /usr/lib, /usr/local/lib…
To list the libraries needed by a program:
ldd program
After adding new a new dynamic library, e.g. in /usr/local/lib, you must run, as superuser:
ldconfig -n /usr/local/lib
It is possible, as a user, to tell linux to search libraries in a particular place, using the LD_LIBRARY_PATH variable. For more information about how dynamic libraries are accessed, consult the manual of ld.so:
man ld.so
Install new software
If it come as a .tar.gz and contain a configure script
tar xzf package.tar.gz cd package ./configure --prefix=$HOME & make & make install
This install the software in your home directory. To install it for every user, you need to omit the prefix option and be root when calling ``make install'’.
If you are on a apt-based system (Debian, Ubuntu):
sudo apt install packagename
If you have the .deb file:
sudo dpkg -i file.deb
If you are on a rpm-based linux system, to install an rpm file:
rpm -i package.rpm
To check if the package is correctly installed:
rpm -V package
To remove it:
rpm -e package
Check if a software package is installed
To check if, say, ghostscript is installed:
rpm -q ghostscript
You can get the list of all installed packages:
rpm -qa
Configure Multiple Displays
Use the programs xranrd and arandr
xrandr --output eDP1 --rotate left
Get back your sanity with a productive environment
- Use a window manager. The tiling window manager i3wm fits the bill
- use git for projects
LIENS
https://openclassrooms.com/courses/reprenez-le-controle-a-l-aide-de-linux
Digital Unix Command and Shell User’s Guide
Rute user’s tutorial and exposition
Linux tutorials for absolute beginner
The Linux documentation project