{"id":24291087,"url":"https://github.com/anr007/shacks","last_synced_at":"2026-05-06T00:06:42.004Z","repository":{"id":46601983,"uuid":"227795213","full_name":"anr007/shacks","owner":"anr007","description":"Commonly used bash commands","archived":false,"fork":false,"pushed_at":"2022-10-05T19:39:01.000Z","size":37,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-06T03:36:02.798Z","etag":null,"topics":["bash","hacktoberfest","linux","shell","unix"],"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/anr007.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}},"created_at":"2019-12-13T08:44:57.000Z","updated_at":"2023-04-25T06:49:17.000Z","dependencies_parsed_at":"2023-01-19T07:15:30.514Z","dependency_job_id":null,"html_url":"https://github.com/anr007/shacks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/anr007/shacks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anr007%2Fshacks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anr007%2Fshacks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anr007%2Fshacks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anr007%2Fshacks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anr007","download_url":"https://codeload.github.com/anr007/shacks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anr007%2Fshacks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32672688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-05T11:29:49.557Z","status":"ssl_error","status_checked_at":"2026-05-05T11:29:48.587Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","hacktoberfest","linux","shell","unix"],"created_at":"2025-01-16T13:58:15.002Z","updated_at":"2026-05-06T00:06:41.990Z","avatar_url":"https://github.com/anr007.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# ShellHacks\n\n### Show all active connections with their port information\n\n```\nsudo netstat -tulpn\n```\n\n- netstat (**NET**work **STAT**istics)\n- -t TCP (Shows TCP connections)\n- -u UDP (Shows UDP connections)\n- -l listening (State = LISTEN)\n- -p program (Shows Program Name/PID)\n- -n numeric (Ex: Shows localhost as 127.0.0.x)\n\n### Archive using tar\n\n```\ntar -czvf archive-name.tar.gz /path/to/directory-or-file-to-be-archived\n```\n\n- tar (**T**ape **AR**chiver)\n- -c create (archive)\n- -z gzip (use gzip compression format)\n- -v verbose (list all files processed)\n- -f file archive (use file archive, tar can also write archives to tapes!)\n\n```\ntar --exclude=path/to/unnecessary/files-or-dirs --exclude=regex -czvf archive-name.tar.gz /path/to/input1 /path/to/input2\n```\n\n- path to exclude an entire directory must not end with a trailing **/**\n- regex can be like '\\*.sh' which will exclude all files ending with .sh\n- inputs can be files or directories or both\n\n### Extract tarballs using tar\n\n```\ntar -xzvf archive-name.tar.gz\n```\n\n- -x extract (given archive)\n\n```shell\ntar -xzvf archive-name.tar.gz -C /path/to/output-directory\n```\n\n- -C change to directory\n\n### Peek contents of tarballs\n\n```\ntar -tvzf archive-name.tar.gz\n```\n\n- -t list the contents of an archive\n\n### Split files using split\n\n```\nsplit -b SIZE -d -a NUM input_file output_chunks_prefix\n```\n\n- split - split a file into pieces\n- -b put SIZE bytes per output file. Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000)\n- -d use numeric suffixes starting at 0, not alphabetic\n- -a generate suffixes of length NUM (default 2)\n\n```\nsplit -n N -de -a NUM input_file output_chunks_prefix\n```\n\n- -n generate N chunks output files based on input file size\n- -e do not generate empty output files with '-n'\n\n```\nsplit -l N -d -a NUM input_file output_chunks_prefix\n```\n\n- -l put N lines/records per output file\n\n### Split files using csplit\n\n```\ncsplit input.txt --suppress-matched -k -z -f output -b '%02d.txt' '%.%' '/-*-/' '{*}'\n```\n\nExplanation:\n\nsplits 'input.txt' repeatedly at lines matching pattern similar to '---------' represented by the regex '/-\\*-/' excluding the first line of input.txt and the lines matching pattern, rest are written to files named 'output01.txt', 'output02.txt' etc..\n\n- csplit - split a file into sections determined by context lines\n- '-' can be used to read from stdin\n- '/regex/[offset]' - outputs the contents to a file till the line matching the pattern\n- '%regex%[offset]' - ignore the line(s) matched by the pattern\n- '{repeat-count} - repeat the previous pattern repeat-count additional times\n- --suppress-matched do not output lines matching the specified pattern\n- -k do not remove already generated output files when errors are occur in the process\n- -z suppress zero-length output files\n- -f prefix of output\n- -b suffix format of output\n\n### Merge files using cat\n\n```\ncat f1 f2 \u003e merged_file\n```\n\n- cat - concatenate files and print on the standard output\n- \\\u003e redirect stdout to target_file\n\n```\ncat f?? \u003e merged_file\n```\n\n- f?? - matches file names having any two characters starting with f like f01,fab,fa1 etc..\n\n```\ncat f* \u003e merged_file\n```\n\n### Pull data from remote using scp\n\n```\nscp -i key.pem -P 22 remote-user@remote-address:/full/path/to/remote/file /local/path/to/save/file\n```\n\n```\nscp -i key.pem -P 22 -r remote-user@remote-address:/full/path/to/remote/dir /local/path/to/save/dir\n```\n\n- scp - secure copy (remote file copy program)\n- -i identity_file (directly passed to ssh)\n- -r recursively copy entire directories (follows sym links encountered)\n- -P port (specifies the port to connect to on the remote host)\n\n### Push data to remote using scp\n\n```\nscp -i key.pem /path/to/local/file remote-user@remote-address:/full/remote/path/to/save/file\n```\n\n```\nscp -i key.pem -r /path/to/local/dir remote-user@remote-address:/full/remote/path/to/save/dir\n```\n\n### One-line info of any bash utility\n\n```\nwhatis utility_name\n```\n\n- whatis - display one-line manual page descriptions\n\n### Create files of specific size\n\n```\ntruncate -s SIZE target_file\n```\n\n- truncate - shrink or extend the size of a file to the specified size\n- -s set or adjust the file size by SIZE bytes (K,M,G,T or KB,MB,GB,TB etc.. units can be used to override)\n\n```\nhead -c SIZE /dev/urandom \u003e target_file\n```\n\n- head - output the first part of files\n- -c print the first SIZE bytes of each file (K,M,G,T or KB,MB,GB,TB etc.. units can be used to override)\n- \\\u003e redirect stdout to target_file\n\n### Pull data from remote using rsync\n\n```\nrsync -e \"ssh -i key.pem\" -Pzavh remote-user@remote-address:/full/path/to/remote/file/or/dir /local/path/to/save/file/or/dir\n```\n\n- rsync - a fast, versatile, remote (and local) file-copying tool\n- -e specify command for remote shell to use\n- -P show progress, keep partially transferred files\n- -z compress file data during the transfer\n- -a archive mode, equals -rlptgoD\n- -v verbose\n- -h output numbers in a human-readable format\n\n### Push data to remote using rsync\n\n```\nrsync -e \"ssh -i key.pem\" -Pzavh /local/path/to/save/file/or/dir remote-user@remote-address:/full/remote/path/to/save/file/or/dir\n```\n\n### Search for files/directories\n\n```\nfind -L /path/to/search -maxdepth 5 -type f -iname \"*.pdf\" -mtime -7 -size +25k -ls\n```\n\n- find - search for files in a directory hierarchy\n- -L Follow symbolic links\n- -maxdepth Descend at most levels (a non-negative integer) levels of directories below the starting-points\n- -type **f** for regular file, **d** for directory, **s** for socket\n- -iname Base of file name, the match is case insensitive\n- -mtime File's data was last modified **n\\*24** hours ago (+n for greater than n, -n for less than n, n for exactly n)\n- -size File uses n units of space, rounding up (k for for kibibytes[KiB], M for mebibytes[MiB], G for gibibytes[GiB])\n- -ls if matches, list current file in **ls -dils** format on standard output\n\n### Execute any command with stdin as input\n\n```\nls *.txt | xargs -d \"\\n\" -t tar -cvzf text_files.tar.gz\n```\n\n- xargs - build and execute command lines from standard input (default command is _/bin/echo_)\n- -d delim Input items are terminated by the specified character\n- -t Print the command line on the standard error output before executing it\n\n### View bad login attempts\n\n```\nlastb username\n```\n\n- lastb - shows a log of the /var/log/btmp file, which contains all the bad login attempts\n- login attempts can be verified [here](https://blackhat.directory)\n\n### Show currently logged in users\n\n```\nw\n```\n\n- w - Show who is logged on and what they are doing\n\n### Kill a process\n\n```\nkill -s Signal PID\n```\n\n- kill - send a signal to a process\n- -s signal or value\n- use **man 7 signal** for indepth info on all types of signals\n- the signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored\n\n| Signal  | Value | Action      | Comment                                            |\n| ------- | ----- | ----------- | -------------------------------------------------- |\n| SIGTERM | 15    | Termination | Graceful, Default                                  |\n| SIGKILL | 9     | Termination | Forceful                                           |\n| SIGINT  | 2     | Termination | Interrupt from keyboard, 'Ctrl + C'                |\n| SIGHUP  | 1     | Termination | Hang UP, Terminal running the process disconnected |\n| SIGQUIT | 3     | Termination | Quit from keyboard + Coredump, 'Ctrl + \\\\'         |\n| SIGTSTP | 20    | Stop        | Graceful, 'Ctrl + Z'                               |\n| SIGSTOP | 19    | Stop        | Forceful                                           |\n| SIGCONT | 18    | Continue    | Continue if Stopped; else, Ignore                  |\n\n### Kill a task\n\n```\nkillall -s Signal -v -y 10m -u root PNAME\n```\n\n- killall - kill processes by name\n- -s signal\n- -v report if the signal was successfully sent\n- -y kill processes younger than TIME (in s,m,h,d,w,M,y)\n- -o kill processes older than TIME (in s,m,h,d,w,M,y)\n- -u kill only process(es) running as USER\n- PNAME name of the processes to be signalled\n- -l list all known signal names\n\n```\npkill -ce -SIGTERM -u root,daemon -n PATTERN\n```\n\n- pkill - look up or signal processes based on name and other attributes\n- -c count of matching processes\n- -e display what is killed\n- -SIGNAL\n- -n select most recently started (newest)\n- -o select least recently started (oldest)\n- -u match by USERS\n- PATTERN used for matching names of processes to be signalled\n- use `pgrep -a -u root PATTERN` to check processes matched by the pattern\n- -a list PID and full command line (pgrep only)\n- -l list PID and process name (pgrep only)\n\n### Find and Replace in files\n\n```\nSRC='Replace Me' \\\n TGT=\"I'm Replaced\" \\\n grep -RiIl \"$SRC\" | xargs -rt sed -i \"s#$SRC#$TGT#g\"\n```\n\n- -R **grep:** Read all files under each directory, recursively. Follow all symbolic links\n- -i **grep:** Ignore case distinctions, so that characters that differ only in case match each other\n- -I **grep:** Process a binary file as if it did not contain matching data\n- -l **grep:** Print the name of each matched input file\n- -r **xargs:** If the standard input does not contain any nonblanks, do not run the command\n- -t **xargs:** Print the command line on the standard error output before executing it\n- -i **sed:** edit files in place\n- sed alternate delimiters: \\_ | # ; [space]\n\n### Count lines\n\n```\ncat file.txt | wc -l\n```\n\n- wc - word, line, character, and byte count\n- -l The number of lines in each input file is written to the standard output\n\n### Append to file\n\n```\necho 'export KUBE_EDITOR=\"nano\"' \u003e\u003e ~/.bashrc\n```\n\n- `\u003e\u003e` append or create\n- `\u003e` overwrite or create\n\n### Exec file\n\n```\nsource ~/.bashrc\n```\n\n```\n. ~/.bashrc\n```\n\n- source - Execute commands from a file in the current shell\n\n### Time any command\n\n```\ntime -p find -iname '*.sh'\n```\n\n- time - run programs and summarize system resource usage\n- -p **time:** format output string for conformance with POSIX standard 1003.2\n- -iname **find:** match is case insensitive\n\n### Tempmark current dir\n\n```\ndirs -v\n```\n\n- dirs - display the list of currently remembered directories\n\n```\npushd .\n```\n\n- pushd - stores the current directory for use by the popd command, and then changes to the specified directory.\n\n```\npopd\n```\n\n- popd - changes the current directory to the directory that was most recently stored by the pushd command.\n\n### Total disk usage\n\n```\ndu -sh /path\n```\n\n- du - estimate file space usage\n- s summarize\n- h print sizes in human readable format\n\n### List attached disks\n\n```\nlsblk -pmf\n```\n\n- lsblk - list block devices\n- p Print full device paths\n- m Output info about device owner, group and mode\n- f Output info about filesystems\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanr007%2Fshacks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanr007%2Fshacks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanr007%2Fshacks/lists"}