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!
Let's get some bash-fu in here!
Let's get some bash-fu in here!
¯\_(ツ)_/¯ It works on my machine...
Re: Let's get some bash-fu in here!
That CTRL+U/Y thing is rather interesting
run the previous command replacing "typo" with "fixed"
copy filename and add extension".ori", maybe as cute as TAB completion?
Run a command multiple times using variables from a file
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
Check SHA256 sum of a file, nice bold red for a matching sum and nothing for a failed match.
run the previous command replacing "typo" with "fixed"
Code: Select all
^typo^fixed^
Code: Select all
cp filename{,.ori}
Code: Select all
< variable.list xargs -I{} command {}
take you back to your previous directory
Code: Select all
cd -
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]
[img]http://i911.photobucket.com/albums/ac320/stuphsack/Sig.jpg[/img]
- bad_brain
- 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!
one command chain I find very useful is:
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.
Code: Select all
cat logfile | awk '{print $1}' | sort | uniq -c | sort -nr > newfile
Re: Let's get some bash-fu in here!
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
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...