Posts

Showing posts from October, 2017

SKIP a particular number of lines, use $ tail -n +

sudo redirection permission denied | use tee or script

The trouble is, this contrived example doesn't work: sudo ls -hal /root/ > /root/test.out I just receive the response: -bash: /root/test.out: Permission denied There are multiple solutions: Run a shell with sudo and give the command to it by using the  -c  option: sudo sh -c 'ls -hal /root/ > /root/test.out' Create a script with your commands and run that script with sudo: #!/bin/sh ls -hal /root/ > /root/test.out Run  sudo ls.sh . See Steve Bennett's  answer  if you don't want to create a temporary file. Launch a shell with  sudo -s  then run your commands: [nobody@so]$ sudo -s [root@so]# ls -hal /root/ > /root/test.out [root@so]# ^D [nobody@so]$ Use  sudo tee  (if you have to escape a lot when using the  -c  option): sudo ls -hal /root/ | sudo tee /root/test.out > /dev/null The redirect to  /dev/null  is needed to stop  tee  from outputting to the screen. To  a...

vi/vim :move -2 :move +2 - moves line search text and replace :%s/search/replace/gc

vi :move -2 :move +2 - moves line in vi search text and replace :%s/search/replace/gc Here "pattern" represents the old string and "replace" represents the new string. For example, to replace each occurrence of the word "lemon" in a line with "orange," type: :s/lemon/orange/ The syntax for replacing  every  occurrence of a string in the  entire  text is similar. The only difference is the addition of a "%" in front of the "s": :%s/pattern/replace/

ssh-add -l | ssh-add -x | ssh-add -X | ssh-copy-id |

After installing Ubuntu 16.04 I recreated my ssh keys as I forgot to back them up, but whenever I attempt to use ssh I get  sign_and_send_pubkey: signing failed: agent refused operation  this is slightly annoying as it lets me through to my ssh server, but git refuses to push code using ssh. I have already pushed the keys to the server by using  ssh-copy-id . Looks like an  ssh-agent  is running already but it can not find any keys attached. To solve this add the private key identities to the authentication agent like so: ssh-add ssh-add # This will load your key into the ssh-agent session so that you can login to hosts without requiring your passphrase each time Then you can  ssh  into your server. in addition, you can see the list of fingerprints of all identities currently added by: ssh-add -l Example with ssh-add ~/.ssh/id_rsa Ensure the ssh-agent is running: If you are using the Git Shell that's installed with GitHub Deskt...

eval | c="echo"; a1="Hello, "; a2="World!"; eval $c $a1 $a2

eval  is a  builtin  command of the  Bash  shell. It  concatenates  its  arguments  into a single  string , joining the arguments with spaces, then  executes  that string as a bash command. It's similar to running  bash -c " string " , but  eval  executes the command in the current shell  environment  rather than creating a  child  shell  process . The  eval  command is not used very often in bash. In other shells, it can be used in  scripts  as a way to get the  value  of a  variable  whose name is not known until the script is run. In bash, however, this can be accomplished with variable indirection using the syntax: ${! varname } Examples c="echo"; a1="Hello, "; a2="World!"; eval $c $a1 $a2 Assign strings to variables  c ,  a1 , and  a2 . Then, use  eval  to evaluate those arguments and join them into a single s...

rpm yum apt-get dpkg SwitchingToUbuntu/FromLinux/RedHatEnterpriseLinux

Task Red Hat/Fedora Ubuntu Adding, Removing and Upgrading Packages Refresh list of available packages Yum refreshes each time it's used apt-get update Install a package from a repository yum install  package_name apt-get install  package_name Install a package file yum install  package.rpm rpm -i  package.rpm dpkg --install  package.deb Remove a package rpm -e  package_name apt-get remove  package_name Remove a package with configuration files yum remove  package_name apt-get purge  package_name Check for package upgrades yum check-update apt-get -s upgrade apt-get -s dist-upgrade Upgrade packages yum update rpm -Uvh [args] apt-get upgrade Upgrade the entire system yum upgrade apt-get dist-upgrade Package Information Get information about an available package yum search  package_name apt-cache search  package_name Show available packages yum list avail...