You can edit your crontab file with “
crontab -e“. It worked fine as long as I used vim. However, when I switched to emacs and set the
EDITOR environment variable to point to emacs, I couldn’t edit my crontab file normally. Emacs is started in the background and somehow it caused problems.
I made a script for editing my crontab file. This script sets
EDITOR back to vim, thus “
crontab -e” opens vim. Here is the script:
#!/usr/bin/env bash # crontab_e EDITOR=/usr/bin/vim crontab -e
I call this script “crontab_e”, so it’s easy to remember its name.
Ever wondered who (which process) opened a given file? There is a Unix command to answer this question called
lsof (“list open files”). Read more about it at wikipedia.
Execute the following script:
#!/usr/bin/env python3 # who.py def main(): f = open("/tmp/who.txt", "w") input("Press ENTER to continue...") f.close() ##### if __name__ == "__main__": main()
Make it executable and run it. In another terminal issue the command “
lsof /tmp/who.txt“. You’ll get a similar output:
$ cd /tmp $ lsof who.txt COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME python3 1288 jabba 3w REG 0,32 0 27 who.txt $ ps 1288 PID TTY STAT TIME COMMAND 1288 pts/0 S+ 0:00 python3 ./who.py
who.txt was opened by the process with PID 1288, which is the
If you have Dropbox installed on several machines, sometimes one of the clients litter your Dropbox folder with conflicted copies. Their number can be up to hundred(s). How to get rid of them?
First, locate the conflicted copies:
$ cd ~/Dropbox # or wherever your Dropbox folder is $ find . | grep "conflicted copy"
Investigate the result and make sure they can be deleted.
# one more check: $ find . | grep "conflicted copy" | while read i; do echo $i; done # if you are absolutely sure, delete them: $ find . | grep "conflicted copy" | while read i; do echo $i; \rm "$i"; done
Notice that “
$i” is between quotes since these filenames contain spaces.
You have a media file (audio, video, image) and you want to get some detailed information about it: duration, bit rate, resolution, etc. How to extract these pieces of information?
Use the MediaInfo project. You can install it via your package manager and you will get a command called “mediainfo”.
$ mediainfo movie.avi
General Complete name : movie.avi Format : AVI Format/Info : Audio Video Interleave Format profile : OpenDML Format settings : rec File size : 1.27 GiB Duration : 2h 29mn Overall bit rate : 1 218 Kbps Writing application : AVI-Mux GUI 184.108.40.206, Feb 16 201019:42:50 Video ID : 0 Format : MPEG-4 Visual Format profile : Advanced Simple@L5 Format settings, BVOP : 2 Format settings, QPel : No Format settings, GMC : No warppoints Format settings, Matrix : Default (H.263) Muxing mode : Packed bitstream Codec ID : XVID Codec ID/Hint : XviD Duration : 2h 29mn Bit rate : 1 086 Kbps Width : 720 pixels Height : 304 pixels Display aspect ratio : 2.35:1 Frame rate : 23.976 fps Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Compression mode : Lossy Bits/(Pixel*Frame) : 0.207 Stream size : 1.13 GiB (89%) Writing library : XviD 64 Audio ID : 1 Format : MPEG Audio Format version : Version 1 Format profile : Layer 3 Mode : Joint stereo Mode extension : MS Stereo Codec ID : 55 Codec ID/Hint : MP3 Duration : 2h 29mn Bit rate mode : Constant Bit rate : 128 Kbps Channel(s) : 2 channels Sampling rate : 48.0 KHz Compression mode : Lossy Stream size : 136 MiB (11%) Alignment : Aligned on interleaves Interleave, duration : 747 ms (17.92 video frames) Interleave, preload duration : 216 ms Title : mp3 Writing library : LAME3.99r Encoding settings : -m j -V 4 -q 2 -lowpass 17 -b 128
pandoc input.txt -o output.pdf
By the way, pandoc can convert from / to lots of file formats.
cat file.txt | shuf
For more alternatives, see the comments at the bottom of this page.
You have a long text file and you want to process it parts by parts. For instance, you want to work with the first 50 lines, then with lines 51-100, etc.
cat file.txt | sed -n '1,50p' # or: sed -n '1,50p' file.txt