Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for 6 Unix tools you need to know about
Mithil Poojary
Mithil Poojary

Posted on • Edited on

     

6 Unix tools you need to know about

1. column

I, as a programmer, do not mind those nastily formatted tabular data, like...

Pid Name %CPU1230 Firefox 15600 Code 12809 Terminal 1.2
Enter fullscreen modeExit fullscreen mode

But when I learnt about column, I was pretty fascinated by how easy it is to make it neat!

column <file_name> -tPid   Name       %CPU1230  Firefox    15600   Code       12809   Terminal  1.2
Enter fullscreen modeExit fullscreen mode

2. less

How many times did you feel disgusted by the mess you made on your terminal screen? Maybe you printed a huge file or did ps aux. I have been there.
A very neat solution is to use less. The text is displayed upon applying a filter for paging through text one screenful at a time.

You don't have any clutter on your terminal once you exit less.

3. sort

Imagine having a file with ID and Names like this.

16  Siri20  Cortana13  Mithil9   Jarvis
Enter fullscreen modeExit fullscreen mode

A quick sort on the IDs would be super helpful right?

sort <file_name> -n9   Jarvis13  Mithil16  Siri20  Cortana
Enter fullscreen modeExit fullscreen mode

4. tr

I can't really think of a better situation to use this right now, but hey it works.
Say you have to replace the occurence of a character. tr (translate) does this for you.

echo "This is a sentence" | tr " " "\n"Thisisasentence
Enter fullscreen modeExit fullscreen mode

5. head and tail

Head and tail themselves are pretty solid tools, but together they have their own use case.

Say you want the 11th line in a text file. You can do this by :

head <file_name> -n 11 | tail -n 1
Enter fullscreen modeExit fullscreen mode

That was all for this post. What are your preferred helpful Unix tools?

Photo by Karl Pawlowicz on Unsplash

Top comments(5)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
_garybell profile image
Gary Bell
A Senior Developer working mostly with PHP and JavaScript, with a bit of Python thrown in for good measure, all on Linux. My tooling is simple, it's GitLab and JetBrains where possible.
  • Location
    Swansea, UK
  • Work
    Senior Developer
  • Joined

I'm a huge fan of the (relatively) straight forwardfind command. When coupled with-exec, you can do some pretty creative things, fairly quickly.

I've usedfind historically for getting backup files which are more than 2 weeks old, and deleting them. It's a simple way of keeping backups from taking over hard drive space, without needing to do everything manually

CollapseExpand
 
geekypandey profile image
Anurag Pandey
  • Location
    Pune, India
  • Joined

That coupling withexec takes it to another level. What are your other favourites?

CollapseExpand
 
_garybell profile image
Gary Bell
A Senior Developer working mostly with PHP and JavaScript, with a bit of Python thrown in for good measure, all on Linux. My tooling is simple, it's GitLab and JetBrains where possible.
  • Location
    Swansea, UK
  • Work
    Senior Developer
  • Joined

Going to be boring and saygrep. I think a lot of people have it as a go-to tool to filter the returned output of a command into something useful.

I don't spend a lot of time in the terminal using Linux/Unix specific commands. Most of my time on the terminal is spend using Git, and increasingly more often, redis-cli

Thread Thread
 
geekypandey profile image
Anurag Pandey
  • Location
    Pune, India
  • Joined

Yeah.git grep is super handy to find files with particular snippets of code.

I started with competitive programming recently and I used to save code asfilename.py and thentestcase_filename for the testcases.ls | grep -v testcase came in handy to code files and clear the noise.

CollapseExpand
 
josephj11 profile image
Joe
Was a professional programmer for 17 years. Now I dabble in FOSS on Linux.
  • Location
    Amherst, NY, USA
  • Work
    Software Engineer at JPmicrosystems DBA
  • Joined

I don't use tr very often, but it's very handy for getting rid of odd binary codes in text files and translating between upper and lower case. I have seen much fancier uses of it, but don't recall any at the moment.

Here's a quick way to show someone the format of a data file without revealing any sensitive data.

#!/bin/bash## Obsfucate a text file## 11/25/2013## Thanks to D. Joe on the WNYLUG list## For sharing the format of a text file with sensitive data in itif [ -z "${1}" ]then  IN="/dev/stdin"else  if [ ! -r "${1}" ]  then    echo "Can't read [${1}]"    exit 1  fi  IN="${1}"fiif [ -z "${2}" ]then  OUT="/dev/stdout"else  OUT="${2}"fitr 'a-z' 'A-Z' < "${IN}" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'AAAAAAAAAAAAAAAAAAAAAAAAAA' | tr '0123456789' '9999999999' > "${OUT}"

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Mainly working with Python. Feels amazing to be an Open-Sourcerer!
  • Location
    Mumbai, India
  • Education
    B.E. Information Technology
  • Work
    Student
  • Joined

More fromMithil Poojary

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp