Useful tips for linux
Among the various commands available in Linux, we have summarized useful things.
Ctags
Ctags is a programming tool that generates an index (or tag) file of names found in source and header files of various programming languages. Depending on the language, functions, variables, class members, macros and so on may be indexed. These tags allow definitions to be quickly and easily located by a text editor, a code search engine, or other utility. Alternatively, there is also an output mode that generates a cross reference file, listing information about various names found in a set of language files in human-readable form.
Creating ctags file
# Ctags (-R option might not work in AIX)
ctags -f $HOME/src/ctags -R $HOME/src
# Ctags for AIX
ctags -w -f $HOME/src/ctags \
/usr/include/*.[c,h] \
$HOME/src/admin/*.[c.h] \
$HOME/src/common/*.[c.h] \
$HOME/src/spp/*.[c.h]
Add ctags to .vimrc
set tags+=${HOME}/src/tags
Get any key event
function pa() {
read -n1 -r -p "Press any key"
}
Grep
- ‘-i’ : Ignore case distinctions in both the PATTERN and the input files.
- ‘-e’ : same as egrep
- ‘-v’ : Invert the sense of matching, to select non-matching lines.
- ‘-l’ : list the matching files
- ‘-A’ : Print NUM lines of trailing context after matching lines.
- ’–color’
Find
# Find recently modified c files within 1 day
find . -name "*.[c,h]" -mtime 1 | xargs -altr
Watch
# Monitoring
watch -d -n 1 'date'
curl
-d, --data: <data> Send specified data in POST request.
-H, --header: <header> Headers to supply with request.
-X, --request: The request method to use. ex) GET, POST
curl examples
# GET
curl -d "key1=value1&key2=value2" \
-H "Content-Type: application/x-www-form-urlencoded" \
-X GET http://localhost:8000/data
# POST
curl -d "key1=value1&key2=value2" \
-H "Content-Type: application/x-www-form-urlencoded" \
-X POST http://localhost:8000/data
# POST + JSON
curl -d '{"key1":"value1", "key2":"value2"}' \
-H "Content-Type: application/json" \
-X POST http://localhost:8000/data
# Using file
curl -d @aa.json \
-H "Content-Type: application/json" \
-X GET http://localhost:8000/data
Leave a comment