Let's get some bash-fu in here!

Don´t be shy, Linux is fun! =)
Post Reply
User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Let's get some bash-fu in here!

Post by Gogeta70 »

So, I love learning new ways to be more efficient when using the linux terminal, so why don't we start a thread showing some neat tricks to make life a little easier? I'll start

1. Are you half-way through typing out a long command, but forgot to make a directory, or cd into one, etc? You're in luck! Press CTRL+U to "store" a command and remove it from the prompt, type out your forgotten command "mkdir foo; cd foo/", then CTRL+Y to "restore" your command.

2. This one is a bit more common than #1. Instead of pressing the up arrow to get the previous command, you can type !! and the shell will substitute your last command in place of it.

3. Pressing ALT+. will place the last "segment" of your previous command at the end of your current command. Pressing it repeatedly will go back further into your bash history.

4. Do you compile your own binaries on occasion? I really hate it when I get a compile error about a missing header file (eg. missing module.h) without any indication as to what package i need to install. Recently, I found out about the apt-file utility. It searches the package cache file list and lists all packages containing a file specified on the command line. Ex: apt-file search module.h

5. This one is awesome. Some commands output a lot of information without very good spacing. One such command is "mount" to list all mounted media. Try this: "mount | column -t". You're welcome.


Well, that's all I can think of at the moment. I'll add more if I think of any. Now, show me what y'all got!
¯\_(ツ)_/¯ It works on my machine...

User avatar
lilrofl
Siliconoclast
Siliconoclast
Posts: 1363
Joined: 28 Jan 2009, 17:00
15
Location: California, USA
Contact:

Re: Let's get some bash-fu in here!

Post by lilrofl »

That CTRL+U/Y thing is rather interesting

run the previous command replacing "typo" with "fixed"

Code: Select all

^typo^fixed^
copy filename and add extension".ori", maybe as cute as TAB completion?

Code: Select all

cp filename{,.ori}
Run a command multiple times using variables from a file

Code: Select all

< variable.list xargs -I{} command {}
Probably these two go without saying, but I didn't know them at one point and use them frequently today:
take you back to your previous directory

Code: Select all

cd -
Check SHA256 sum of a file, nice bold red for a matching sum and nothing for a failed match.

Code: Select all

sha256sum file_you_are_checking | grep sum_you_are_checking
knuffeltjes voor mijn knuffel
[img]http://i911.photobucket.com/albums/ac320/stuphsack/Sig.jpg[/img]

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Re: Let's get some bash-fu in here!

Post by bad_brain »

one command chain I find very useful is:

Code: Select all

cat logfile | awk '{print $1}' | sort | uniq -c | sort -nr > newfile
it processes an access log file (any file with IPs in it) and lists the IP addresses sorted by number of appearance...it also displays how often the IPs appear.
Image

User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Re: Let's get some bash-fu in here!

Post by Gogeta70 »

Nice! Some pretty nifty commands in here.

I also remembered another:

You can use 'pushd' to move to another directory, and 'popd'' to go back to your last directory

Code: Select all

root@aj-laptop:~/seclists/Passwords# 
root@aj-laptop:~/seclists/Passwords# pushd ~/kali/usr/share/metasploit-framework/data/wordlists/
~/kali/usr/share/metasploit-framework/data/wordlists ~/seclists/Passwords
root@aj-laptop:~/kali/usr/share/metasploit-framework/data/wordlists# ls
total 2148
-rw-r--r-- 1 root root    791 Apr 12  2017 adobe_top100_pass.txt
-rw-r--r-- 1 root root   7568 Apr 12  2017 av_hips_executables.txt
-rw-r--r-- 1 root root    754 Apr 12  2017 av-update-urls.txt
-rw-r--r-- 1 root root   7418 Apr 12  2017 burnett_top_1024.txt
-rw-r--r-- 1 root root   3585 Apr 12  2017 burnett_top_500.txt
... more stuff here ...
root@aj-laptop:~/kali/usr/share/metasploit-framework/data/wordlists# popd
~/seclists/Passwords
root@aj-laptop:~/seclists/Passwords# 
¯\_(ツ)_/¯ It works on my machine...

Post Reply