cancel
Showing results for 
Search instead for 
Did you mean: 
DavidOBrien
Starfighter Starfighter
Starfighter
  • 3,422 Views

Which really useful command did you learn today?

Linux is full of really useful commands, and I discover new ones all the time. Today I learned this:

$ > filename

Why is this useful? In my case, <filename> already existed but I wanted it to remain and be completely empty. I toyed with echo and touch but that left a space in the file or took too many keystrokes (I'm lazy):

$ echo '' > filename
$ rm filename; touch filename

This simple command left me with exactly what I needed.

So, what really useful command did you learn today? 

Labels (1)
6 Replies
josemdiaza
Flight Engineer
Flight Engineer
  • 3,417 Views

Very intersting. Today I learned how to use the oc subcommand edit. You can edit a YAML or JSON resource with edit. It prompts a Vim interface to edit and commit the changes :)

 

oc edit

carlos_arias
Moderator
Moderator
  • 2,560 Views

That is just perfect for my laziness @DavidOBrien, thanks!

RHCA - Level III
Free software for free people
Trevor
Starfighter Starfighter
Starfighter
  • 2,534 Views

Hello gang,

I feel a little like a neophyte mentioning this one, but it has to
do with the "date" command.   I was revisiting the "aureport"
utility today, looking at some things involving my old friend 
the Linux audit daemon - auditd.  While going through the man
page of "aureport", I saw an example involving the "date" command,
that didn't tie in directly with auditing, however, I saw something
in the command that I didn't recall ever using.  What was it?  It
involved the  -d "string"  component of the "date" command.

To fast-forward a little bit here, I didn't know that this kind of 
flexibility existed with the "date" command:

$   date  -d  "10 seconds ago"          // Nothing magical about the number 10.
                                                            //  It's just the first number that came to my brain

I thought that was so cool.  So, from there I did a little research to 
see what other expressions I could place within the string, and found
that this component of the "date" command is indeed flexible with the
content within the quotes.  There are very few explicit examples in the
man page of the "date" command, as well as the info documention for
the "date" command.  So, I just put on my "mad scientist" coat, and cooked
up a few.

$  date         // started here for my reference point
$  date  -d  "5 seonds ago"
$  date  -d  "5 minutes ago"
$  date  -d  "5 days ago"
$  date  -d  "5  weeks ago"
$  date  -d  "5  months ago"
$  date  -d  "5 years ago"
$  data  -d  "5 years 3 months ago"

I stopped with the last one because I could see myself
getting pulled away from what I was supposed to be
focusing on - auditing.  But I know that I will come back
around to exploring the valid syntax that can appear as
the actual string content.  In fact, I'm very tempted to 
ask for contributions from the community, collecting the
input, and compiling a cheatsheet of sorts.  

I've been using the "date" command since my UNIX days,
and I just don't recall any of this.  Yes, UNIX!!!!   You know
there was Betamax before VHS tapes, right   Okay, let me
stop with that.  I might be too far off-road right now.

Who would have thunk it that this kind of discovery would 
have been made after 40+ years on this beat.  I almost feel
like I'm in the company of that British doctor that asked the
question "What is this fungus", and that led to his discovery 
of penicillin

Anyway, that's the useful item that I learned today. 
I"m done

 

Trevor "Red Hat Evangelist" Chandler
0 Kudos
Fran_Garcia
Starfighter Starfighter
Starfighter
  • 2,526 Views

Hey Trevor,

 

if you want to really go into the rabbit hole, you can check relative dates like:

➜ date -d "next monday"
2023-04-17T00:00:00 CEST

➜ date -d "monday 2 weeks ago"
2023-04-03T00:00:00 CEST

Even some basic dates arithmetic:

➜ date -d '2023-04-17 - 33 days'
2023-03-15T00:00:00 CET

 

There are more details about this in the info page for date: 'info date" -> "29.7 Relative items in date strings"

0 Kudos
Chetan_Tiwary_
Community Manager
Community Manager
  • 2,505 Views

I got to know about this command : lolcat

It is a command-line tool in Linux that is used to display text with rainbow-colored text or background colors. It is typically used for fun or for visual emphasis in text-based outputs, such as terminal output or log files. 

eg if you do anything like this :

# man ls | lolcat
# ps | lolcat
# date | lolcat
# cal | lolcat

 

 

It will give you rainbow colored output which looks quite fun. You can use lolcat with cat to animate a text in rainbow of colours.

Tags (3)
0 Kudos
ipalagin
Flight Engineer Flight Engineer
Flight Engineer
  • 2,477 Views

How to check TCP network connection, using "echo" command only - it's great for scripts and minimal installations without network tools installed:

$ echo > /dev/tcp/<IP address or host name>/<port> || echo DOWN

For example, can I access 192.168.10.101:8080 from my server?

$ echo > /dev/tcp/192.168.10.101/8080  || echo DOWN

# no errors

 

 

 

 

 

 

 

Join the discussion
You must log in to join this conversation.