DEV Community

Anton
Anton

Posted on

Three hacks and commands to use in your terminal.

The first one is:

du -sh */ | sort -rh | head -6

This command will show 6 heaviest folders.

du - disk usage

| - pipe. Which works like pipes in Elixir and Elm.

Basically, the output of the first function becomes an input for the next function and so on.

head - shows only a certain amount of output.

The second one:

Turn this >

A terminal with a long line before the dollar sign

into this >

a terminal with just a dollar sign

Just add this to your ~/.bashrc:

PS1='\$ '

After that you need to restart your bash:

source ~/.bashrc

Also, there are different ways to restart your bash.

There are more ways you can set this up check out this overflow to find out more.

The third one:

Creating folders with a pattern. Recently I had to create 8 folders for my codewars challenges:

mkdir kyu_{1..8}

I unfortunately don't remember where I find out about this command.

Oh, I just found it. It's here.

Latest comments (14)

Collapse
 
bdmorin profile image
Brian

github.com/uutils/coreutils this rust written du is crazy fast. Also ncdu is great because it maintains an index, you can update it via cron, and use it in prompt lines - requires tokyocabinet though, which some people dislike.

if you have multiple cores, check out this rust rewrite of du.
github.com/sharkdp/diskus
It's unreasonably fast.

Thanks for the tips!

Collapse
 
antonrich profile image
Anton

But I will probably later look more into github.com/vmchale/tin-summer

Collapse
 
antonrich profile image
Anton

Do you know what it means?

diskus: could not contents of directory './.gvfs'
Collapse
 
bdmorin profile image
Brian

Did you get this figured out?

Thread Thread
 
antonrich profile image
Anton

No, I haven't yet. Mainly, because diskus doesn't do the same thing in comparison to du.
Maybe I missed some options but diskus weighs my whole drive. I need to weigh the folders separately.

Collapse
 
antonrich profile image
Anton

Gosh, I like Rust. Thanks, for sharing.

Collapse
 
shubhamkhandare profile image
Shubham Khandare

Can you help with second one.. Is there any way to do it for session with command?

Collapse
 
antonrich profile image
Anton

Yes.

Just enter this in your terminal as a command (don't put it in your bashrc file):

PS1='\$ '

Collapse
 
shubhamkhandare profile image
Shubham Khandare

but that does not work on unix like environments !

Thread Thread
 
antonrich profile image
Anton

I'm sorry. I'm kind of unfamiliar with unix. Do you mean on systems like BSD?

Thread Thread
 
shubhamkhandare profile image
Shubham Khandare

Yes. I was on HP-UX.

Collapse
 
tux0r profile image
tux0r

du -sh */ | sort -rh | head -6

sort: illegal option -- h

Just add this to your ~/.bashrc:

You should add that a major part of your article is only applicable to bash users to your tags or the headline.

mkdir kyu_{1..8}

At least this is portable. ;-)

Collapse
 
antonrich profile image
Anton

Do you use zsh?

Collapse
 
tux0r profile image
tux0r

I use the POSIX standard shell, the ksh, on most of my servers. (The notable exception being one which has the tcsh, but I usually don't try to use it for scripting.)