Awesome Commands Series

gkzz
2 min readFeb 11, 2019

--

Summary of useful commands

#1

How To Run sudo command With No Password

$ sudo vim /etc/sudoers
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL #Default
ubuntu ALL=(ALL) NOPASSWD:ALL #Add

Sources;
How to run sudo command with no password?

#2

Change Defalut Editor

If your defalut editor is “nano” not “vim”, you should type the command bellow;

$ sudo update-alternatives — config editorThere are 5 choices for the alternative editor (providing /usr/bin/editor).Selection    Path                Priority   Status
------------------------------------------------------------
* 0 /bin/nano 40 auto mode #Defalut
1 /bin/ed -100 manual mode
2 /bin/nano 40 manual mode
3 /usr/bin/code 0 manual mode
4 /usr/bin/vim.basic 30 manual mode
* 5 /usr/bin/vim.tiny 10 manual mode #Modify

sources;

How to change visudo editor from nano to vim? [duplicate]

#3

A Shortcut To mkdir foo And Immediately cd into it like this

$ mkdir foo && cd foo$ mkdir foo; cd $_

sources;

Is there a shortcut to mkdir foo and immediately cd into it?

#4

mv all files that match specific pattern

$ find ./ -name ‘<ptn>’ | xargs -I% mv % ./<target directory>/

sources;

find で検索したファイルを一括で移動(mv)させる

#5

How To Append Current DateTime From A Variable To A Filename

#!/bin/bash
#example.sh
nowDatetime=`date ‘+%Y%m%d_%H%M%S’`;
filename=”$HOME/log/history_$nowDatetime.log”
history 10000 > $filename

sources;

Appending a current date from a variable to a filename

#6

How do I find all files containing specific text on Linux?


grep -rnw ‘/path/to/somewhere/’ -e ‘pattern’
-r or -R is recursive,-n is line number, and-w stands for match the whole word.-l (lower-case L) can be added to just give the file name of matching files.

sources;

How do I find all files containing specific text on Linux?

https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on-linux

P.S. How to display code blocks in Medium

Windows: Control + Alt + 6

Mac: Command + Option + 6

Linux: Control + Alt + 6

--

--

gkzz
gkzz

Written by gkzz

🇯🇵 #SoftwareDeveloper #MeijiUniv @apc_tweet Opinions are my own. #Geek #ギークハウス大倉山 #gkz https://gkzz.github.io/

No responses yet