In this post i have listed common Linux commands which are very helpful for .Net developer. In most cases asp.net core developers work on Windows. Main reason is that previously .Net was only supported on Windows only, and the most helpful tool, The great IDE, Visual Studio, was only supported on windows.
Now things have changed. .Net Core is cross platform. Available for Windows, Mac and Linux. There is Visual Studio Code, available for all three platforms. However, Visual Studio is still not supported on Linux. But again, .Net core has made easy to develop .net application on Linux machine.
Now, developers who are using Linux for first time, they feel very uncomfortable switching from Windows. And things gets really DARK, when they start working on Linux server, without GUI. Everything need execute commands to perform any task. I have been through that phase. Even today I forget many Linux commands and all I do is repeated search for small Linux commands.
So, I have listed the general day to day Linux commands:
Login as root in terminal
To act as root in terminal, you can use below command:
This will convert the terminal “$” sign to “#” sign. It means now you are acting as root in terminal.
Copy & Move
To copy a file from one location to another, Here is the command:
cp firstfile secondfile
Move command is user for two purpose: Move and Rename.
So this will move first file to other location:
mv /path/to/oldfile /path/to/newfile
And this will rename the file:
mv oldfilename newfilename
The same command is used for move and rename. You can also use it to move and rename it in same command.
Deleting files & folders
Note: Be careful while removing files and folder, because once deleted they can not be recovered. Not like Windows bin.
To delete a folder or directory which contains other files and folders, use below command:
rm -r foldername
Here -r flag means recursively.
Same way you can delete file.
If you want to delete multiple files, then write each file name with space between them when using this command.
Directory Read/Write Permission
On Linux, mostly developer from windows environment face file read and write permission. It’s the case mostly with writing log files, or any file like file upload. In Linux, every user is needed to have permission to read and write file, and the process which runs the application is also act as user, that user is ‘www-data’.
Giving asp.net core (apache www-data user) write permission:
sudo chown -R www-data:www-data /var/www/example.com/public_html sudo chmod -R 770 /var/www/example.com/public_html
Running Visual Studio Code as root
Although it’s not recommended to run VS code as root, but sometimes we need to run it. For that you can this command:
sudo code --user-data-dir="~/.vscode-root"
This article is in progress, and i will update it with more commands that is used by developer.