tar -pczf MyFile.tar.gz /home/user/myDirectory/ --exclude="./directoryToExclude1" --exclude="./directoryToExclude2"Note that there is no "/" at the end of the path to the directory to exclude!
Friday, June 21, 2019
Wednesday, July 25, 2018
Swap columns in text file with awk
To swap column 2 and 3 in a 4 column file:
OFS: indicates the separator character(';' in the example above).
FILE: original file.
NEW_FILE: new file with the changes.
awk -F, '{print $1,$3,$2,$4}' OFS=; "FILE" > NEW_FILE
where:OFS: indicates the separator character(';' in the example above).
FILE: original file.
NEW_FILE: new file with the changes.
Friday, April 27, 2018
Shell Script 'action' Command
'action' is defined inside a library called functions. You have to source your script first with this library in order to use it. This library is a distro distribution dependent and none of these distro libraries are compatible with the others. In Ubuntu is /lib/lsb/init-functions, SuSE has /etc/rc.status and in Centos is /etc/rc.d/init.d/functions. Some distributions don't use it at all.
Example of 'action':
Example of 'action':
# Source function library. . /etc/rc.d/init.d/functions # Now you can use action: action $"Perform an action:" /bin/trueIn Centos 7, 'action' definition inside /etc/rc.d/init.d/functions is as the following:
# Run some action. Log its output.
action() {
local STRING rc
STRING=$1
echo -n "$STRING "
shift
"$@" && success $"$STRING" || failure $"$STRING"
rc=$?
echo
return $rc
}
Wednesday, April 25, 2018
Set or Change System Hostname
This will return the current hostname
$ hostname MyHostameTo set hostname immediately:
$ hostname [MY_HOSTNAME]This will change the hostname of your system immediately, but the original hostname will be restored upon next reboot. To set hostname to be permant follow the instructions below. For systemd based distributions(newer version of different Linux distributions such as latest Ubuntu, Debian, CentOS, Fedora, RedHat, etc. ) use the hostnamectl command:
$ sudo hostnamectl set-hostname [MY_HOSTNAME]For sysvinit(in short init) based distributions(older linux distributions) edit /etc/hostname:
# vim /etc/hostnameAdd a new line for the hostname in /etc/hosts:
# vim /etc/hosts
127.0.0.1 [MY_HOSTNAME]And run:
# /etc/init.d/hostname restartFor RHEL/CentOS based systems that use init, edit /etc/sysconfig/network:
# vi /etc/sysconfig/network
/etc/sysconfig/network NETWORKING=yes HOSTNAME="[MY_HOSTNAME]" GATEWAY="192.168.0.1" GATEWAYDEV="eth0" FORWARD_IPV4="yes"
Thursday, March 1, 2018
shmget errno 22 EINVAL: "Invalid Argument"
The man page says:
This means that a memory segment still persists in the system. If your process is no longer running, run the ipcs command and remove the segment with ipcrm.
EINVAL A new segment was to be created and size < SHMMIN or size > SHMMAX, or no new segment was to be created, a segment with given key existed, but size is greater than the size of that segment.
This means that a memory segment still persists in the system. If your process is no longer running, run the ipcs command and remove the segment with ipcrm.
[root@myhost]# ipcs ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x74010241 2818048 root 600 4 0 0x7401026c 2162689 root 600 4 0 0x00000000 3178498 root 644 52 2 0x74010240 2785283 root 600 4 0 0x00000000 3211268 root 644 16384 2 0x00000000 3244037 root 644 268 2 0x750ca262 3440646 root 644 2043293648 0 ------ Semaphore Arrays -------- key semid owner perms nsems 0x000000a7 0 root 600 1 ------ Message Queues -------- key msqid owner perms used-bytes messages 0x7504d462 9568256 root 666 0 0 0x7504d562 9601025 root 666 0 0 0x7504d662 2686978 root 666 0 0 0x7504d762 2719747 root 666 0 0 0x7504d862 5373956 root 666 0 0 0x7504d962 5406725 root 666 0 0 0x75108a62 9502726 root 666 0 0 0x000002bd 9535495 root 666 0 0 [root@myhost]# ipcrm -m 3440646 [root@myhost]# ipcs ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x74010241 2818048 root 600 4 0 0x7401026c 2162689 root 600 4 0 0x00000000 3178498 root 644 52 2 0x74010240 2785283 root 600 4 0 0x00000000 3211268 root 644 16384 2 0x00000000 3244037 root 644 268 2 ------ Semaphore Arrays -------- key semid owner perms nsems 0x000000a7 0 root 600 1 ------ Message Queues -------- key msqid owner perms used-bytes messages 0x7504d462 9568256 root 666 0 0 0x7504d562 9601025 root 666 0 0 0x7504d662 2686978 root 666 0 0 0x7504d762 2719747 root 666 0 0 0x7504d862 5373956 root 666 0 0 0x7504d962 5406725 root 666 0 0 0x75108a62 9502726 root 666 0 0 0x000002bd 9535495 root 666 0 0 [root@myhost]#
tar with multiple directories and file locations
tar -czvf mytargz.tar.gz /path1/to/dir1 /path2/to/dir2 /path3/to/dir3
Friday, December 1, 2017
Mocking a Web Service with NetCat
Write the web service's response(xml, json, plain text) in a file, and then run the following in a terminal:
In this case, the web service mock is listening in the port 9999. Just change the port as your needs.
$ while true; do echo -e "HTTP/1.1 200 OK\r\n\r\n$(cat wsresponse.file)" | nc -l 9999; doneWhere wsresponse.file is the file with the web service response.
In this case, the web service mock is listening in the port 9999. Just change the port as your needs.
Popular Posts
-
To uninstall driver from unixODBC using odbcinst, execute: $ sudo odbcinst -u -d -n [ Driver_name ] FreeTDS has been deleted (if it existed...
-
- Delete branch of current project: git remote remove origin - Add current project to a branch: git remote add origin [remote repository] ...
-
1. Show the status(how many new files, deleted files, modified files, etc.): $ git status 2. Add all files to the project: $ git add -A th...
-
Designed by Freepik You have a group of files and some of them are compressed with zip or gz and you want to search for a specific tex...
-
Testing TCP connection Create TCP listener: $ nc -l 9999 Create TCP Client: $ nc -vt 192.168.5.12 9999 Ncat: Version 6.40 ( http://nma...
-
Write the web service's response(xml, json, plain text) in a file, and then run the following in a terminal: $ while true; do echo -e...
-
To swap column 2 and 3 in a 4 column file: awk -F, '{print $1,$3,$2,$4}' OFS=; " FILE " > NEW_FILE where: OFS: ind...
-
Just do: source ~/.bashrc or: . ~/.bashrc
-
'action' is defined inside a library called functions. You have to source your script first with this library in order to use it. T...
-
Create a new branch and move your project to it: $ git checkout -b [New Branch] If you have modified or created files, add them to the pro...
Recent Posts
Categories
.bash
.bashrc
action
awk
bash
branch
changes
chmod
chown
color
column
command line
commands
commit
compress
compress files
compressed
config
console
convert
copy
CR-LF
create
cut
delete
desktop
diff
directories
directory
dos
driver
erase
error
etc
except
exclude
extract files
fetch
find
format
git
gnome
gz
hash
hostname
init.d
install
integrity
ipc
kernel
linux
list
ls
md5
mock
msgget
mysql
netcat
networking
newlines
odbc
odbcinst
openvpn
owner
passwd
paste
permissions
queue
quick guide
rc.d
readline
reboot
recursively
redhat
release
remove
rm
route
routing
scp
screen
script
selinux
shell
shmget
shortcuts
shutdown
SIOCDELRT
start
stderr
stdout
sublime text
sublime text 3
swap
sysctl
tail
tar
tar.gz
tcp
tcpdump
tee
terminal
test
truncate
udp
uname
uninstall
unixODBC
user
useradd
version
view
vpn
webservice
zgrep
zip
Unordered List
Text Widget
Pages
About Me
Search This Blog
Powered by Blogger.