Showing posts with label Unix. Show all posts
Showing posts with label Unix. Show all posts

Thursday, January 30, 2025

A proposal for file extension of back up files

There are several extensions used for backup files: 

  • .0, .1, etc.
  • .old, 
  • .bak, 
  • .backup, 
  • .bkp, 
  • ~ suffix
  • .orig
  • .save
  • .baka, etc. 

Based on Reddit votes, the most used is .bak; therefore, we should use the extension used by common sense.

choosing backup filename extension

(Proposed) Specification:

  1. A backup file must be named with the extension .bak
  2. If there are multiple backups, the next backup extension must be added with an integer, e.g., .bak1, .bak2, etc.
  3. The above rules also apply for folder or directory, e.g., folderA.bak, dirB.bak1.

Finding all backup files

To find all backup files, simply use a shell command

$ ls *.bak*
a.bak  a.bak0  a.bak1  a.bak2


Update: 
  • 2026/03/23: Sometimes, I found adding .0, .1, is simpler and shorter. 

Thursday, April 14, 2022

Menemukan dan Menghapus file (ekstensi tertentu, ukuran tertentu)

Menemukan fail

Pola: find [nama-direktori] -name [nama-file]

Contoh

pc060066:~$ find . -name tes.txt
./tes.txt

Tanda titik setelah find menunjukkan current directory (dalam hal ini /home/$USER).

Menemukan dan menghapus fail

Pola: find [nama-direktori] -name [nama-file-yang-dihapus] -delete

Contoh

pc060066:~$ cp tes.txt tes-del.txt
pc060066:~$ find . -name tes-del.txt
./tes-del.txt
pc060066:~$ find . -name tes-del.txt -delete
pc060066:~$ find . -name tes-del.txt
Terlihat file yang dihapus (tes-del.txt) tidak ada setelah perintah di atas.


Menemukan dan menghapus fail ekstensi tertentu

Pola: find [nama-direktori] -name ['*.ext'] -delete

pc060066:~$ mkdir test
pc060066:~$ cd test
pc060066:test$ ls
pc060066:test$ touch test{1..5}.txt
pc060066:test$ ls
test1.txt  test2.txt  test3.txt  test4.txt  test5.txt
pc060066:test$ touch readme.md
pc060066:test$ ls
readme.md  test1.txt  test2.txt  test3.txt  test4.txt  test5.txt
pc060066:test$ find . -name '*.txt'
./test1.txt
./test3.txt
./test2.txt
./test5.txt
./test4.txt
pc060066:test$ find . -name '*.txt' -delete
pc060066:test$ ls *.txt
ls: cannot access '*.txt': No such file or directory
Jangan lupa single quote diantara ekstensi ('*.txt'); untuk ekstensi lainnya tanda quote ini tidak perlu. Contohnya *.wav. Kita juga bisa mencari (dan menghapus) file ekstensi tertentu dengan nama tertentu. Contohnya menemukan (dan menghapus) file dengan nama berakhiran *_cd16k.wav.


Menemukan dan menghapus fail ukuran tertentu

Pola: find [nama-direktori] -name [nama-file-opsional] -size [ukuran, -, +] -delete

Contoh:
pc060066:test$ find . -size 4c
./test8.txt
pc060066:test$ find . -size 4c -delete
pc060066:test$ ls
1001_DFA_ANG_XX.wav  test1.txt  test3.txt  test5.txt  test7.txt
readme.md            test2.txt  test4.txt  test6.txt
pc060066:test$ find . -size -10c # find below 10 bytes
./test6.txt
./test1.txt
./test3.txt
./readme.md
./test2.txt
./test5.txt
./test4.txt
pc060066:test$ find . -size -10c -delete # delete below 10 bytes
pc060066:test$ ls
1001_DFA_ANG_XX.wav  test7.txt
pc060066:test$ find . -size +10c -delete # delete above 10 bytes
pc060066:test$ ls
Jadi tanda "-" untuk kurang dari dan "+" untuk lebih dari ukuran file yang dikehendaki. Tidak ada tanda maka hasilnya pada rentang nilai tersebut. Misal 10c untuk 10 bytes, 10k untuk 10 kilobytes, termasuk 10001 bytes sampai dengan 10999 bytes. 

Menghapus file kosong

Pola: find [nama-direktori] -empy -delete
Contoh:
pc060066:test$ find . -empty
./test10.txt
./test6.txt
./test1.txt
./test3.txt
./test2.txt
./test8.txt
./test5.txt
./test9.txt
./test4.txt
./test7.txt
pc060066:test$ find . -empty -delete
pc060066:test$ ls

Menghapus direktori kosong

Pola: find [nama-direktori] -d -empty -delete 

Contoh:
pc060066:test$ ls -ltr
total 20
drwxrwxr-x 2 bagus bagus 4096  4月 14 15:33 test_dir_5
drwxrwxr-x 2 bagus bagus 4096  4月 14 15:33 test_dir_4
drwxrwxr-x 2 bagus bagus 4096  4月 14 15:33 test_dir_3
drwxrwxr-x 2 bagus bagus 4096  4月 14 15:33 test_dir_2
drwxrwxr-x 2 bagus bagus 4096  4月 14 15:33 test_dir_1
pc060066:test$ find . -type d
.
./test_dir_5
./test_dir_4
./test_dir_2
./test_dir_1
./test_dir_3
pc060066:test$ find . -type d -empty
./test_dir_5
./test_dir_4
./test_dir_2
./test_dir_1
./test_dir_3
pc060066:test$ find . -type d -empty -delete
pc060066:test$ ls
Bedakan dengan perintah sebelumnya untuk file, untuk direktori kita perlu argumen "-type d".

Menemukan dan menghapus kecuali


Pola: find [nama-direktori] not -name [kecuali] -delete

Contoh:
find . not -name "*_mono.wav" -delete
Argumen "not" bisa diganti dengan tanda seru "!" agar lebih singkat. Untuk folder yangt tidak kosong (directory is not empty), kita perlu menggunakan "rm -fr" sebagai pengganti argumen "-delete".
find . -mindepth 1 ! -name "kecuali-direktori1" ! -name "*.py" ! -name "KECUALI.md" ! -name "kecuali-direktori2" -exec rm -rf {} +

Saturday, February 05, 2022

Fuzzy search with FZF

`history` itu penting. Dengannya kita bisa mencari perintah-perintah apa saja yang telah kita panggil. Berikut contohnya.
$ history
# output
..
 1978  cd
 1979  cd github/CSS
 1980  cd github/CCS/
 1981  git pull
 1982  cd scripts/
 1983  ls
 1984  cp create_csv_split.py create_csv_split_ccs.py
 1985  code create_csv_split_ccs.py 
 1986  python3.8 -m IPython
 1987  cd
 1988  ls /groups/gac50538/
 1989  cd github/CSS/
 1990  ls
 1991  cd ..
 1992  ls
 1993  cd CCS/
 1994  ls
 1995  code csv/train_dataset_ccs.csv 
 1996  python3 -m IPython
 1997  python3 -m IPython
 1998  ssh 192.168.244.64
 1999  history
Lebih mudah lagi, perintah `history` bisa kita panggil dengan jalan pintas Ctrl-R. Kita bisa menggunakan Ctrl-R lagi untuk berputar (cycle) ke `history` selanjutnya. 

FZF 

FZF membuat `history` terlihat usang. Atau bisa saja dikatakan memambah kemampuan `history` agar lebih bertenaga lagi: "fuzzy search". Perhatikan potongan video berikut.
sudo apt install fzf
fzf
# Ctrl-R
Untuk bisa menggunakan fitur tersebut, yakni mengganti Ctrl-R dari `history` ke `fzf`. Kita perlu tambahkan dua baris berikut ke .bashrc.
source /usr/share/doc/fzf/examples/key-bindings.bash
#source /usr/share/doc/fzf/examples/completion.bash
Dari mana saya tahu agar menambahkan dua baris di atas? Dari output `apt-cache show fzf`, seperti disarankan di laman resminya.
Demikian, Ctrl+R sekarang sudah berganti ke `fzf` dari `history`. Selamat jalan `history`.

Beberapa shortcut bermanfaat selain Ctrl+R:
  • Alt + C: untuk memilih direktori (contoh: ketik `cd` kemudian Alt + C)
  • Ctrl + T: untuk memilih file  
Update:  
2025/11/27: Untuk Ubuntu versi 24.04 baris kedua di atas tidak perlu ditambahkan pada `.bashrc`.
 

Wednesday, September 27, 2017

Git Undo

Tulisan ini adalah kelanjutan dari tulisan sebelumnya tentang bekerja dalam tim dengan Git disini. By default, git tidak memiliki fitur git undo karena sebenarnya fitur utama dari git adalah kemampuannya untuk meng-undo secara tak terbatas. Cara meng-undo-nya bergantung pada treatment apa yang sudah anda lakukan: mengundo commit, atau kembali pada versi sebelumnya (misal: karena anda tidak puas pada versi sekarang). Berikut caranya.

A post shared by Bagus Tris Atmaja (@bagustris) on

Friday, April 07, 2017

Tutorial wget

Definisi
Saya sangat menyukai wget. Ketika saya stuck dengan firefox dan chromium karena keduanya semakin lama semakin berat, biasanya saya berpindah ke konsole dan mendownload semua yang saya inginkan dengan wget. Wget merupakan no-interactive network downloader yang berjalan di terminal Unix. Wget mengambil file dari web (web-get, maybe) dengan protokol http, https dan ftp. Dinamakan non-interaktif karena bisa berjalan dalam proses 'background', artinya user tidak perlu terus menerus login, proses download tetap berjalan, dan bisa mem-pause atau men-start proses download. Berikut adalah tampilan wget ketika saya mendownload suatu file dari internet.

tampilan wget ketika mendownload file

Saturday, October 10, 2015

Running job with proper software version via modulefiles in supercomputer

Motivation

On HPC cluster (high performance computing/supercomputer), it is often to have multiple version of the same software installed. When the user want to use the specific software which the certain library, changing environment variable like $PATH manually is tedious and sometime difficult, the is the common errors during running job in HPC. To solve the problem, corresponding shell script would have to be written for multiple languages. All of these explicit steps are error prone and difficult to maintain. It is also no simple upgrade path. One exist solution is by using modulefiles, a (Unix) tool for dynamic modification of a user's environment.

Module Commands

Here are some module commands:
  • module avail: to check available modulefiles
  • module list: view current active modules
  • module purge: delete currently loaded modules
  • module load <package>: to load default module <package>
  • module load <package/version>: to load module <package> on specific version.
  • module unload <package>: unload the package
  • module show <package>: display command triggered by module load
  • module whatis <package>: display 1-line info about the module
  • module help <package>: need a help?
Related Posts Plugin for WordPress, Blogger...