{"id":16531098,"url":"https://github.com/koushikphy/better-linux","last_synced_at":"2025-07-23T21:38:55.066Z","repository":{"id":106138639,"uuid":"472803178","full_name":"Koushikphy/Better-Linux","owner":"Koushikphy","description":"Commands, tools \u0026 know-how to work with Linux in a better way","archived":false,"fork":false,"pushed_at":"2023-10-26T06:10:26.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-03T09:23:27.706Z","etag":null,"topics":["bash","bash-script","bash-scripts","compression","linux","linux-shell","linux-utilities","linux-utils"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Koushikphy.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-22T14:25:48.000Z","updated_at":"2022-03-22T14:31:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"c3241dea-346b-41cd-9312-131cf898b256","html_url":"https://github.com/Koushikphy/Better-Linux","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Koushikphy/Better-Linux","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Koushikphy%2FBetter-Linux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Koushikphy%2FBetter-Linux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Koushikphy%2FBetter-Linux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Koushikphy%2FBetter-Linux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Koushikphy","download_url":"https://codeload.github.com/Koushikphy/Better-Linux/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Koushikphy%2FBetter-Linux/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266753970,"owners_count":23979145,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","bash-script","bash-scripts","compression","linux","linux-shell","linux-utilities","linux-utils"],"created_at":"2024-10-11T18:07:53.882Z","updated_at":"2025-07-23T21:38:55.044Z","avatar_url":"https://github.com/Koushikphy.png","language":null,"readme":"- [Useful commands](#useful-commands)\n  - [File/folder listing](#filefolder-listing)\n  - [File copy/transfer](#file-copytransfer)\n  - [File operations](#file-operations)\n  - [miscellaneous](#miscellaneous)\n- [File \\\u0026 Folder compression](#file--folder-compression)\n  - [`gzip`](#gzip)\n  - [`xz`](#xz)\n  - [`tar`](#tar)\n  - [`zip`](#zip)\n- [Process Handling](#process-handling)\n- [Linux utilities you should use instead](#linux-utilities-you-should-use-instead)\n  - [`fd`: replacement for `find`](#fd-replacement-for-find)\n  - [`exa`: replacement for `ls`](#exa-replacement-for-ls)\n  - [`gdu`: replacement for `du`](#gdu-replacement-for-du)\n  - [`fzz`: replacement for `Ctrl+R`(reverse-i-search)](#fzz-replacement-for-ctrlrreverse-i-search)\n  - [`bat`: replacement for `cat`](#bat-replacement-for-cat)\n  - [Terminal file managers](#terminal-file-managers)\n- [Useful bash variables](#useful-bash-variables)\n- [Bash color schemes](#bash-color-schemes)\n- [Things to do after installing ubuntu](#things-to-do-after-installing-ubuntu)\n\n\n## Useful commands\n### File/folder listing\n\n1. size of the current directory\n```\ndu -shx\n```\n\n2. size of folders in current directory\n```bash\ndu -d1 -h\ndu -d1 -h | sort -h   # sort according to size\n```\n\n3. list all files with size greater than 1GB (using [fd](https://github.com/Koushikphy/Better-Linux#fd-replacement-for-find))\n```bash\nfd -S +1G\n```\n\n4. total size of all files named `data.dat`\n```bash\nfd data.dat -X du -ch\nfd -e txt -X du -ch    # files with `txt` extension\n```\n\n5. compress all `.txt` files with `xz`\n```bash\nfd -e txt -j 1 -x xz # -j 1 wll launch one instance of `xz`\n```\n\n6. Find multiple patterns with `fd`\n```bash\nfd '(pattern1|pattern2)'\n```\n\n7. Find exact matches with `fd`\n```bash\nfd '^pattern$'\n```\n\n8. tree with file size\n```\ntree -h -d 1 --du /path/to/dir\n```\n\n\n### File copy/transfer\n\n1. Copy files with progress and speed shown:\n```\nrsync -zmavh --progress --stats\n```\n\n2. rsync only copy file with certain extension\ncopy files only with `.sh` [extension](https://stackoverflow.com/questions/11111562/rsync-copy-over-only-certain-types-of-files-using-include-option/11111793)\n```\nrsync -zarvm --include=\"*/\" --include=\"*.sh\" --exclude=\"*\" \"$from\" \"$to\"\n```\n\n\n3. `rsync` only transfer certain files  \nsearch the list of files with `fd` (or `find`) and send it using `rsync`\n```bash\nfd \u003csearch_pattern\u003e | rsync -avm  --progress --stats --files-from=- . $dst\n```\n\n\n### File operations\n1. Replace text in file without opening it\n```\nsed -i \"s/string/replace/g\" file\n```\n2. print two file side by side \n```\npr FILE1 FILE2 -m \n```\n3. Print m to n lines of a file:\n```\nsed -n 'm,np' file\n```\n\n\n### miscellaneous\n\n\n1. set date and time directly from terminal:\n```\nsudo date -s \"$(wget -qSO- --max-redirect=0 google.in 2\u003e\u00261 | grep Date: | cut -d' ' -f5-8)Z\"\n```\n\n\n2. Check diskIO of processes\n```\nsudo iotop\n```\n\n3. use function with `xargs`\n```\nmoveRun() {\n  cwd=$(pwd)\n  cd $1\n  pwd\n  cd $cwd\n}\n\nexport -f moveRun\nls -d */ | xargs -n1 bash -c 'moveRun \"$@\"' _\n```\n\n4. tail with timestamp\n```\ntail -f outputfile | xargs -IL date +\"%I:%M:%S %p\"\n```\n\n\n5. Quickly benchmark file I/O speed\n```\n# clear cache\necho 3 | sudo tee /proc/sys/vm/drop_caches\n# write speed\ndd if=/dev/zero of=./output conv=fdatasync bs=384k count=1k\n# read speed\ndd if=./output of=/dev/null bs=384k count=1k\n# clear\nrm output\n```\n\n6. Check location of some running command\n```\nls -l /proc/\u003cproc_id\u003e/exe\n```\n\n7. Mount remote with `sshfs`\n```bash\nsshfs user@ip:remote_directory local_directory\n```\n\n8. Wait for a process to finish with PID\n```bash\ntail --pid=$PID -f /dev/null\n```\n\n\n## File \u0026 Folder compression\n### `gzip` \n\n```bash\ngzip -kv -6 \u003cfilename\u003e\n#or\ngzip -kvr -6 \u003cdirectory\u003e\n```\n`-k` : is to keep the original file after generating the compressed one, by default it removes the original file.   \n`-v` is for `verbose`.   \n`-6` is the (default) compression level, available number are from 1 to 9, 1 being the fastest and 9 meaning the best/slowest compression.   \nFor directory `-r` flag is used for recursive compression.  \n\nDecompress the same with \n```bash\ngzip -d file.gz\n```\n\n- Similar to `gzip` another compression utility `bzip2`. It has similar flags and usage like `gzip`  \n- For parallel gzip use https://zlib.net/pigz/  \n\n\n\n\n### `xz`\n`xz`(`lzma` compression) is better alternative to `gzip` use it with \n```bash\nxz -k -6 -T 3 --verbose \u003cfile\u003e\n```\n`xz` supports parallel processing, use it with `-T 3` with 3 being number of processor.  \n\n- For best possible compression of large files use [lrzip](https://github.com/ckolivas/lrzip)\n\n- [A Quick Benchmark: Gzip vs. Bzip2 vs. LZMA](https://tukaani.org/lzma/benchmarks.html)  \n\n- Which one to use?  \n  * If you want to quickly compress the file and on a limited resource use `gzip`. \n  * If you want the best compression/ smallest file size and have enough RAM and processor available use `xz`  \n\n\u003c!--  - Useful utilities:  \n * Parallel gzip [pigz](https://zlib.net/pigz/)\n  * Long range zip [lrzip](https://github.com/ckolivas/lrzip) --\u003e\n\n\n### `tar`   \n`tar` by itself only archive multiple files or folder into one single file and doesn't compress anything. Then other compression utilities are used to compress the file. Gnu `tar` can handle this whole process on its own. To compress the `sample-folder` into `archive.tar.gz`\n```bash\ntar -zcvf archive.tar.gz sample-folder\n```\n`-z` : Use `gzip` to compress  \n`-c` : Create archive  \n`-v` : Verbose  \n`-f` : Archive file name  \n`-j` : Use `bzip2` utility  \n`-J` : Use `xz` utility  \n`-I` : Specify compression utility, `-I 'gzip -6'` is same as `-z`  \nTo decompress the file into the folder again replace the create (`-c`) with extract (`-x`) flag\n```bash\ntar -xvf archive.tar.gz\n```  \n\nTo list the contents of a compressed file use:\n```bash\ntar -tf file.tar.gz\n```\n\n\n### `zip`  \n```bash\nzip output.zip [filename] [-r folder_name]\n```\nto unzip use  \n```bash\nunzip file.zip [-d destination_folder]\n```\n\n\n## Process Handling\n| Command    |  Description|\n| ----------- | ----------- \n|    `Ctrl+C`     | Kill the current forground processs. (Send SIGINT signale to the process) |\n|    `Ctrl+Z`     | Suspend the current forground processs. (Send SIGSTOP signale to the process) | \n|    `kill \u003cpid\u003e`     | Send signall to a process. Default is SIGTERM. \u003cbr\u003e Use `kill -l` to check the full list of available signal | \n|    `pkill \u003cname\u003e`     | Kill all processes with name \"name\" | \n|    `fg`    | Move jobs to foreground |\n|    `bg`    | Move jobs to background |\n|    `jobs -l`    | List all background jobs for the current shell. |\n|    `pgrep -la \u003cname\u003e` \u003cbr\u003e `top -bc -n1 \\| grep \u003cname\u003e`   | List all jobs with name \"name\" |  \n\n\n\n## Linux utilities you should use instead\nBetter and faster alternative to regularly use bash commands  \n\n### `fd`: replacement for `find`\nInstall with `sudo apt install fd-find` or download the latest release from https://github.com/sharkdp/fd  \nPreferred usage `fd (part of) file_name [-e extension] [-S size_specs] [-x executable {}] [-t d/f] [-E exclude]` \n\n---\n### `exa`: replacement for `ls`  \nDownload latest release from https://github.com/ogham/exa  \nPreferred usage `exa -l -T -L \u003cdepth\u003e --no-user`  \n\n---\n### `gdu`: replacement for `du`\nInstall `gdu` from https://github.com/dundee/gdu#installation.\nPreferred usage `gdu`\n\n\n---\n### `fzz`: replacement for `Ctrl+R`(reverse-i-search)\nInstall with `git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf \u0026\u0026 ~/.fzf/install`  \nNow source the `~/.bashrc` and it will replace the Ctrl+R, bash reverse with `fzf`\n\n---\n### `bat`: replacement for `cat` \nDownload it from https://github.com/sharkdp/bat\n\n---\n### Terminal file managers\n1. lf: https://github.com/gokcehan/lf\n2. ranger: https://github.com/ranger/ranger\n3. nnn: https://github.com/jarun/nnn\n\n\n## Useful bash variables\n\n- `$1`, `$2`, `$3`, ... are the [positional parameters][1].\n- `\"$@\"` is an array-like construct of all positional parameters, `{$1, $2, $3 ...}`.\n- `\"$*\"` is the IFS expansion of all positional parameters, `$1 $2 $3 ...`.\n- `$#` is the number of positional parameters.\n- `$-` current options set for the shell.\n- `$$` pid of the current shell (not subshell).\n- `$_` most recent parameter (or the abs path of the command to start the current shell immediately after startup).\n- `$IFS` is the (input) field separator.\n- `$?` is the most recent foreground pipeline exit status.\n- `$!` is the PID of the most recent background command.\n- `$0` is the name of the shell or shell script.\n\nMost of the above can be found under [Special Parameters][2] in the Bash Reference Manual. There are all the [environment variables set by the shell][3].\n\n## Bash color schemes\n```bash\n# Reset\nColor_Off='\\033[0m'       # Text Reset\n\n# Regular Colors\nBlack='\\033[0;30m'        # Black\nRed='\\033[0;31m'          # Red\nGreen='\\033[0;32m'        # Green\nYellow='\\033[0;33m'       # Yellow\nBlue='\\033[0;34m'         # Blue\nPurple='\\033[0;35m'       # Purple\nCyan='\\033[0;36m'         # Cyan\nWhite='\\033[0;37m'        # White\n\n# Bold\nBBlack='\\033[1;30m'       # Black\nBRed='\\033[1;31m'         # Red\nBGreen='\\033[1;32m'       # Green\nBYellow='\\033[1;33m'      # Yellow\nBBlue='\\033[1;34m'        # Blue\nBPurple='\\033[1;35m'      # Purple\nBCyan='\\033[1;36m'        # Cyan\nBWhite='\\033[1;37m'       # White\n\n# Underline\nUBlack='\\033[4;30m'       # Black\nURed='\\033[4;31m'         # Red\nUGreen='\\033[4;32m'       # Green\nUYellow='\\033[4;33m'      # Yellow\nUBlue='\\033[4;34m'        # Blue\nUPurple='\\033[4;35m'      # Purple\nUCyan='\\033[4;36m'        # Cyan\nUWhite='\\033[4;37m'       # White\n\n# Background\nOn_Black='\\033[40m'       # Black\nOn_Red='\\033[41m'         # Red\nOn_Green='\\033[42m'       # Green\nOn_Yellow='\\033[43m'      # Yellow\nOn_Blue='\\033[44m'        # Blue\nOn_Purple='\\033[45m'      # Purple\nOn_Cyan='\\033[46m'        # Cyan\nOn_White='\\033[47m'       # White\n\n# High Intensity\nIBlack='\\033[0;90m'       # Black\nIRed='\\033[0;91m'         # Red\nIGreen='\\033[0;92m'       # Green\nIYellow='\\033[0;93m'      # Yellow\nIBlue='\\033[0;94m'        # Blue\nIPurple='\\033[0;95m'      # Purple\nICyan='\\033[0;96m'        # Cyan\nIWhite='\\033[0;97m'       # White\n\n# Bold High Intensity\nBIBlack='\\033[1;90m'      # Black\nBIRed='\\033[1;91m'        # Red\nBIGreen='\\033[1;92m'      # Green\nBIYellow='\\033[1;93m'     # Yellow\nBIBlue='\\033[1;94m'       # Blue\nBIPurple='\\033[1;95m'     # Purple\nBICyan='\\033[1;96m'       # Cyan\nBIWhite='\\033[1;97m'      # White\n\n# High Intensity backgrounds\nOn_IBlack='\\033[0;100m'   # Black\nOn_IRed='\\033[0;101m'     # Red\nOn_IGreen='\\033[0;102m'   # Green\nOn_IYellow='\\033[0;103m'  # Yellow\nOn_IBlue='\\033[0;104m'    # Blue\nOn_IPurple='\\033[0;105m'  # Purple\nOn_ICyan='\\033[0;106m'    # Cyan\nOn_IWhite='\\033[0;107m'   # White\n\n```\n\n\nFor a comprehensive index, please see the [Reference Manual Variable Index][4].  \nReference : [StackOverflow][5]\n\n  [1]: https://www.gnu.org/software/bash/manual/html_node/Positional-Parameters.html\n  [2]: https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html\n  [3]: https://www.gnu.org/software/bash/manual/html_node/Shell-Variables.html\n  [4]: https://www.gnu.org/software/bash/manual/html_node/Variable-Index.html\n  [5]: https://stackoverflow.com/questions/5163144/what-are-the-special-dollar-sign-shell-variables\n\n\n## Things to do after installing ubuntu\n- [Things to do after installing ubuntu](afterInstallUbuntu.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoushikphy%2Fbetter-linux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoushikphy%2Fbetter-linux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoushikphy%2Fbetter-linux/lists"}