#+TITLE: bash commands #+DATE: 2021-08-30 #+STARTUP: indent #+OPTIONS: num:nil * DONE work in bash tutorial :LOGBOOK: CLOCK: [2021-09-08 mié 18:52]--[2021-09-08 mié 19:22] => 0:30 CLOCK: [2021-09-04 sáb 16:04]--[2021-09-04 sáb 16:34] => 0:30 CLOCK: [2021-09-04 sáb 15:19]--[2021-09-04 sáb 15:49] => 0:30 :END: * Execute stuffs * Show command history : history The file can be found in the user home: : /home/user/.bash_history ** Convert pdf to text or html using poppler Use poppler and redirect the text to a org file. ~pdftotext~ converts a pdf to "txt" if no other format is specified : pdftotext foo.pdf foo : pacman -S poppler : pdftotext foo.pdf ->> foo.org # first option : pdftotext foo.pdf foo.org # second option Convert pdf to html : pfdftohtml foo.pdf foo.html ** Convert files using pandoc Use pandoc with "-s" flag to produce a standalone document and "-o" to redirect output to a file. In the example a file "foo" is converted from ~odt~ to ~org~ : pandoc -s -o foo.org foo.odt ** Convert files to pdf using libreoffice Convert odt file "tcl_online3.odt" to pdf : libreoffice --headless --convert-to pdf tcl_online3.odt ** Display files Show content of a file. Concatenates and writes file. Using "tac" reverses the result of "cat" command : cat file.txt Using head, tail and less to show parts of files Showing the first two entries #+begin_src bash head -n 2 /etc/hosts #+end_src #+RESULTS: | 127.0.0.1 | localhost | | 127.0.1.1 | myuser | Showing the last two entries #+begin_src bash tail -n 2 /etc/hosts #+end_src #+RESULTS: | ff02::1 | ip6-allnodes | | ff02::2 | ip6-allrouters | #+begin_src bash less /etc/hosts #+end_src #+RESULTS: | 127.0.0.1 | localhost | | | | 127.0.1.1 | myuser | | | | ::1 | localhost | ip6-localhost | ip6-loopback | | ff02::1 | ip6-allnodes | | | | ff02::2 | ip6-allrouters | | | Show content of a zip file using less and pipe "|" #+begin_src bash unzip -l tntvillage_484094.zip | less #+end_src ** Backup a file Using "cp" : cp bbdb{,.bak} : bbdb.bak Backups with tar (tape archiver) Back up of "home" * c = create file * v = verbose * f = write to a file/device * z = compress the file (gzip) "tar.bz" * j = compress the file (bzip2) : tar -czvf /tmp/home.tar.gz /home ** Simple code to encrypt Encrypt: : gpg -c X : gpg X Use the code to remove the original file: : shred --remove X ** Download files This code download the file and the argument ~-O~ is to rename the file #+begin_example wget https://filetodownload.org -O new_file #+end_example * Devices - mount /what /where - what = device name - where = directory - /mnt = devices that mount occasionally - /media = devices that mount frequently : run/$USER/media/$LABEL * List process Use ~ps~, ~top~ or ~htop~ to list process: * ~ps~ reports a snapshot of the current process : ps aux | less * ~top~ display dynamic real-time view of linux process : top * ~htop~ displays an interactive process viewer : htop To kill a process use: : kill [PID] or : pkill [PID] PID = process identificator * Evaluate time to load In emacs: : time emacs --eval '(save-buffers-kill-terminal)' * Cool commands : cal # calendar : clear # clear output : uname # display system information (-r, -p, -a) : wc # wordcount (file name) : date # check the date * References: * [[https://wiki-dev.bash-hackers.org/][The bash hackers wiki]] * [[https://link.springer.com/content/pdf/bfm%3A978-1-4302-6829-1%2F1.pdf?error=cookies_not_supported&code=2e41714e-ca8f-4796-a077-3243c836ec90][Beginning the linux command line]] * [[https://pandoc.org/][Pandoc manual]] * [[https://stackoverflow.com/][stackoverflow]]