Linux useful commands
To avoid googling the same command over and over
Changing default command
I often need, during installations and builds, to change the gcc, g++,python versions. To do that, there is the update-alternatives command
Then we can choose it with configure
Analyzing multiple ROOT files
Usually simulations and data analysis process a lot of separate files with the same structure. To handle them, we can merge them in a single file with the user-friendly command hadd:
which will automatically merge histograms and tree with the same name.
Alternatively, we can analyze them without merging them, with a TChain:
To merge instead TXT or CSV files, simply use the linux built-in command cat:
Syncronizing
Without copying symbolic links:
Note: A trailing slash on a source path means "copy the contents of this directory". Without a trailing slash it means "copy the directory".
Mounting directory
Add source path and target path within /etc/fstab
Create an empty folder in target path. Then, from root launch
Changing permissions
Usually, you can add all permissions of a folder and subfolders to everyone by launching
"r" is reading permissions, "x" is execution and "w" is writing (i.e. changing files or creating new ones).
"u" is the users who owns the files, "g" is his group and "o" are all the other users. For example, to remove writing permission to all users outside the file owner's group:
Screening
Useful when connecting to ssh and launching long jobs, or not wanting to lose history of your session.
Use screen or tmux.
Create a tmux session with
In lxplus, remember to renew permissions with kinit your@CERN.CH -l 24h00m
Detach tmux session with ctrl-b + d
recover your session with tmux a -t 0 (0 being session number)
Kerberos notes
To show all your active keys
klist -A
To destroy all your active keys
kdestroy -A
Find from which folder a screen process is running
In some cases, such as FEDRA scanset reconstruction, the folder a process is running from contains vital information about the process (in this case, the brick currently being analyzed).
In this case, knowing a Process Id (PID, for example from top), you can find the current working directory of the process by launching (example for PID 47963:
It will return the working directory of the process
Opening many files
If you try to have many files opened at once, you get error "Opened many files". You can solve it by ulimit:
Providing output and error logs
Usually, when asking people for help with a bug, we need to provide output file and error file:
Time conflicts between Windows and Linux in dual-boot
Ora solare/ora legale: Windows and Ubuntu report one or two hours differences with respect to each other: manually settting one breaks the other.
Reason: they use two different time systems, Linux by default uses Universal Time Clock (UTC) and Windows uses Real Time Clock(RTC).
Solution: set them to use the same system, either UTC or RTC. I changed Linux to use RTC like Windows, following instructions here: https://wiki.ubuntu-it.org/Installazione/PostInstallazione/ErroreOraWindows
Find package directory
Often, you need to provide the paths to an installed package, usually for compilation. However, you installed it with apt-get install, and you have no idea where it may be hidden. You can ask directly the package manager where it is located:
In Python modules, this is done with the attribute
Last updated
Was this helpful?