Terminal Linux Ubuntu
Tìm kiếm theo noi dung chua trong file trên Linux Ubuntu
You can search recursively i.e. read all files under each directory for a string “192.168.1.5”
$ grep -r "192.168.1.5" /etc/
Search for old command in ubuntu Terminal:
set: sudo chown $USER:$USER ~/.bash_history
Then can use Ctrl+r for searching
List all previous commands:
history
fc -l <linenumber> list all commands from line_number until the end
history | grep <string can tim kiem>
Find a file
Finding by Name
The most obvious way of searching for files is by name.
To find a file by name, type:
This will be case sensitive, meaning a search for "file" is different than a search for "File".
To find a file by name, but ignore the case of the query, type:
If you want to find all files that don't adhere to a specific pattern, you can invert the search with "-not" or "!". If you use "!", you must escape the character so that bash does not try to interpret it before find can act:
Or
Finding by Type
You can specify the type of files you want to find with the "-type" parameter. It works like this:
Some of the most common descriptors that you can use to specify the type of file are here:
Finding by Typef: regular file
d: directory
l: symbolic link
c: character devices
b: block devices
For instance, if we wanted to find all of the character devices on our system, we could issue this command:
We can search for all files that end in ".conf" like this:
Ubuntu bash history with PageUp/PageDown
In /etc/inputrc, uncomment:
# alternate mappings for "page up" and "page down" to search the history
"\e[5~": history-search-backward
"\e[6~": history-search-forward
Restart your shell or use Ctrl+X, Ctrl+R to tell it to re-read.
Last updated