CentOS 6.7 Root user home deleted? - linux

Some how I managed to delete the /root directory, so I went and recreated and set the proper permissions to the file directory. However, my command line is different and instead of showing root#my-machine# I get -bash-4.1#.
How can I fix this?
Thanks

So you deleted /root and now you have -bash-4.1# in your command line huh?
Well this is caused of a missing / corrupt .bashrc (in your case missing) file in /root (.bashrc sources /etc/bashrc which is what sets the prompt). To fix it, you will run the following command which runs when an account is created. Run as the root user (since it is the user having the problem) or you can define the destination path.
command: (make sure you are in /root)
cp -v /etc/skel/.bash* ~/
Exit terminal and log back in.

I was able to fix the error by creating a new .bashrc
Because the /root directory was removed the default .bashrc was deleted.
I fixed it by running
/bin/cp /etc/skel/.bashrc ~/
and then sourcing the new .bashrc file with source ~/.bashrc

Related

How do I move files out of a broken directory in linux?

I know the premise of the question may be confusing, but I want to understand what happened.
Recently I have been experimenting with the rockchip OK3399 single-chip computer(see here) and have installed a linux system on it with TF card installation. Using Putty and connecting with serial protocol, I was able to establish a connection with the OK3399 computer and control it through my laptop.
I am trying to self-learn some linux with the OK3399 system. I created a bash code by the name of displayvids.sh inside the directory /usr/bin, which is meant to take a variable number of pictures with a mipi camera and then save in a directory for work.
I finished writing the code, but for some reason I cannot run the .sh file when my working directory is not the /usr/bin directory, despite /usr/bin being in the %PATH% environment variable. So, I executed the following command:
mv /usr/bin/display* /usr/local/bin
... attempting to move the file to /usr/local/bin instead. The command ran successfully, but when I tried to run the command:
cd /usr/local/bin
It tells me that I cannot cd to bin
As seen from the above image, the /usr/local/bin is not even a directory. Why would mv succeed if the target was not a directory? How can I retrieve my bash file?
Why would mv succeed if the target was not a directory?
mv can also rename files:
mv foo.txt bar.txt
You renamed your script to bin and moved it under /usr/local.
You may want to remember to add a trailing slash next time, to have mv barf if the target isn't a directory:
mv /usr/bin/display* /usr/local/bin/
How can I retrieve my bash file?
Rename it back.
mv bin displayvids.sh
For future reference, you can use the file command to (try to) identify the contents of a file, if it's installed:
file bin
would have probably said bin: Bash script or similar.

How to fix cd command does not work in Kali Linux

This is what happens when i type cd.
kali#kali:~$ cd
kali#kali:~$
Nothing pops out
kali#kali:~$ cd
kali#kali:~$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
kali#kali:~$ pwd
/home/kali
kali#kali:~$ cd Desktop
kali#kali:~/Desktop$ cd
kali#kali:~$
still nothing
Without arguments, cd changes directory to your $HOME directory.
If you look to your output, something has changed. You were in directory Desktop kali#kali:~/Desktop$ and after cd, the shell changed the directory to ~ (kali#kali:~$) which is the $HOME directory of the current user.
By default if the cd command executes with success no output is displayed and the directory is changed, but if you try to change to some directory that does not exist an error message will be output.
For instance, assuming you don't have directory abc in your root, doing the following in a bash shell will output an error:
$ cd /abd
bash: cd: /abd: No such file or directory
In the newest versions of Kali anyway (2020+), there is no cd command. Simply type the directory name (e.g. Downloads -no slashes brackets or flags at all), this is why nothing happens. I've only done this from root but I expect it works the same from a regular user account as well.

Changes to PATH variable not working

For the life of me, I can't seem to add my Quartus bin directory to the PATH variable.
To add for all users, I edited /etc/profile by adding the line below as follows: (opening the file with sudo gedit /etc/profile)
/home/jaco/altera/14.0/quartus/bin/
I close the file, execute . ./etc/profile, after which I execute echo $PATH. This displays the directory I've just added, but when I open another shell and execute echo $PATH again, the directory is gone.
What am I doing wrong?
I have never made changes to /etc/profile but I know that env variables, aliases etc can be added to ~/.bashrc. You usually have to start a new shell or run source ~/.bashrc after editing your .bashrc file to load the new cahnges.
I think you will have to add it to all users. Also (this helps for future accounts) you can add it in your /etc/skel/.bashrc file. That is the skeleton file used when creating new users.

Recycle bin Script in Linux

In my production server, somebody executed rm -rf and my important files are removed permanently. So, I thought of having a recycle bin, so if a user do rmthe file will move to RecycleBin rather than deleting from server. And i've made the below script for it. But I'm getting some error while it executed.
alias rm='/root/remove.sh'
#rm test_file
Now below script will trigger when you type the rm command
#!/bin/bash
dir=$(pwd)
mv $dir/$1 /root/Recyclebin
when the above script is triggered i'm getting the following error.
mv:cannot move '/root/test_file' to '/root/Recyclebin': Not a directory
Now, please suggest is there anyother way to make a recycle bin concept other than this or please help to resolve the error. Thanks in advance.
I'm using CentOS 5.6
Try This
At first create a folder named as MyTrash under /root ie: /root/MyTrash
Then open .bashrc file and write the below line at the bottom of the file.
alias rm='mv -t /root/MyTrash/'
Here -t means
-t, --target-directory=DIRECTORY
move all SOURCE arguments into DIRECTORY
update .bashrc file by running this command source .bashrc
Now if you delete any file using rm command that file will be moved to /root/MyTrash directory

mkdir $HOME/ error

I tried a one line script that worked in one Linux based distro(Linux mint) but doesn't work in another(Fedora). I typed the following line in my bash script.
mkdir $HOME/folder123
The error i receive:
bash: create.sh: No such file or directory
I tried creating a folder myself, it gave me a permission denied?
To clear things hopefully: mkdir is in the script create.sh and i run it in the terminal with the command bash create.sh
If I interpret your post correctly, you have a file create.sh that contains mkdir $HOME/folder123, and you're trying to run it by typing create.sh.
To execute a script, chmod +x yourscript.sh then run it with either ./yourscript.sh if it's in the current directory, or /home/whatever/yourdir/yourscript.sh if it's in another directory.
To make just yourscript.sh work, you have to place it in a directory listen in $PATH.
You can do this by copying it to any of the directories listed in echo $PATH.
Alternatively, you can create a new directory such as mkdir /home/you/bin and then add export PATH="$PATH:/home/you/bin" at the end of your ~/.bashrc. Also make sure ~/.bash_profile contains the line source .bashrc. Then log out and in again.

Resources